summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorKim van der Riet <kpvdr@apache.org>2014-01-16 20:46:24 +0000
committerKim van der Riet <kpvdr@apache.org>2014-01-16 20:46:24 +0000
commite074786f48659961a80f5c333578a7da5ec8629b (patch)
tree8ad7fb86b291ae10899e485892bef6ec795b3bc5
parent2b5c2503c20ff4ec367c805618f3a8f5cab1ce92 (diff)
downloadqpid-python-e074786f48659961a80f5c333578a7da5ec8629b.tar.gz
QPID-5487: [linearstore] Replace use of /dev/urandom with c random generator calls
git-svn-id: https://svn.apache.org/repos/asf/qpid/trunk@1558913 13f79535-47bb-0310-9956-ffa450edef68
-rw-r--r--qpid/cpp/src/qpid/linearstore/ISSUES7
-rw-r--r--qpid/cpp/src/qpid/linearstore/MessageStoreImpl.cpp8
-rw-r--r--qpid/cpp/src/qpid/linearstore/journal/JournalFile.cpp14
-rw-r--r--qpid/cpp/src/qpid/linearstore/journal/jcfg.h13
-rw-r--r--qpid/cpp/src/qpid/linearstore/journal/utils/file_hdr.c17
5 files changed, 28 insertions, 31 deletions
diff --git a/qpid/cpp/src/qpid/linearstore/ISSUES b/qpid/cpp/src/qpid/linearstore/ISSUES
index bcf3290857..8c5b08bb61 100644
--- a/qpid/cpp/src/qpid/linearstore/ISSUES
+++ b/qpid/cpp/src/qpid/linearstore/ISSUES
@@ -24,7 +24,7 @@ Current/pending:
Q-JIRA RHBZ Description / Comments
------ ------- ----------------------
5359 - Linearstore: Implement new management schema and wire into store
- 5360 - Linearstore: Evaluate and rework logging to produce a consistent log outputConsistent logging
+ 5360 - Linearstore: Evaluate and rework logging to produce a consistent log output
5361 - Linearstore: No tests for linearstore functionality currently exist
* No existing tests for linearstore:
** Basic broker-level tests for txn and non-txn recovery
@@ -39,8 +39,12 @@ Current/pending:
* Empty file pool status and management
5464 - [linearstore] Incompletely created journal files accumulate in EFP
5479 1053701 [linearstore] Using recovered store results in "JERR_JNLF_FILEOFFSOVFL: Attempted to increase submitted offset past file size. (JournalFile::submittedDblkCount)" error message
+ * Probablilty: 2 of 600 (0.3%) using tx-test-soak.sh
5480 1053749 [linearstore] Recovery of store failure with "JERR_MAP_NOTFOUND: Key not found in map." error message
+ * Probability: 6 of 600 (1.0%) using tx-test-soak.sh
+ * If broker is started a second time after failure, it starts correctly and test completes ok.
5484 1035843 Slow performance for producers
+ svn r.1558592 fixes an issue with using /dev/random as a source of random numbers for Journal serial numbers.
- 1036026 [LinearStore] Qpid linear store unable to create durable queue - framing-error: Queue <q-name>: create() failed: jexception 0x0000
UNABLE TO REPRODUCE - but Frantizek has additional info
- 1039522 Qpid crashes while recovering from linear store around apid::linearstore::journal::JournalFile::getFqFileName() including enq_rec::decode() threw JERR_JREC_BAD_RECTAIL
@@ -49,6 +53,7 @@ Current/pending:
- 1039525 Qpid crashes while recovering from linear store around apid::linearstore::journal::jexception::format including enq_rec::decode() threw JERR_JREC_BAD_REC_TAIL
* Possible dup of 1039522
* May be fixed by QPID-5483 - waiting for needinfo
+ 5487 - [linearstore] Replace use of /dev/urandom with c random generator calls
Fixed/closed:
=============
diff --git a/qpid/cpp/src/qpid/linearstore/MessageStoreImpl.cpp b/qpid/cpp/src/qpid/linearstore/MessageStoreImpl.cpp
index 3df194d479..483b494c2c 100644
--- a/qpid/cpp/src/qpid/linearstore/MessageStoreImpl.cpp
+++ b/qpid/cpp/src/qpid/linearstore/MessageStoreImpl.cpp
@@ -66,7 +66,13 @@ MessageStoreImpl::MessageStoreImpl(qpid::broker::Broker* broker_, const char* en
jrnlLog(qpid::linearstore::journal::JournalLog::LOG_NOTICE),
mgmtObject(),
agent(0)
-{}
+{
+ // Test of values for QLS_RAND_SHIFT1, QLS_RAND_SHIFT2 and QLS_RAND_MASK
+ if((((uint64_t)RAND_MAX << QLS_RAND_SHIFT1) ^ ((uint64_t)RAND_MAX << QLS_RAND_SHIFT2) ^ (RAND_MAX & QLS_RAND_MASK)) != 0xffffffffffffffffULL) {
+ THROW_STORE_EXCEPTION("[linearstore] 64-bit random number generation alignment error");
+ }
+ ::srand(::time(NULL));
+}
uint32_t MessageStoreImpl::chkJrnlWrPageCacheSize(const uint32_t param_, const std::string& paramName_)
{
diff --git a/qpid/cpp/src/qpid/linearstore/journal/JournalFile.cpp b/qpid/cpp/src/qpid/linearstore/journal/JournalFile.cpp
index 129a9145d0..1b2025bd5a 100644
--- a/qpid/cpp/src/qpid/linearstore/journal/JournalFile.cpp
+++ b/qpid/cpp/src/qpid/linearstore/journal/JournalFile.cpp
@@ -279,18 +279,8 @@ const std::string JournalFile::getFileName() const {
//static
uint64_t JournalFile::getRandom64() {
- int randomData = ::open("/dev/urandom", O_RDONLY);
- if (randomData < 0) {
- throw jexception(); // TODO: Complete exception details
- }
- uint64_t randomNumber;
- ::size_t size = sizeof(randomNumber);
- ::ssize_t result = ::read(randomData, (char*)&randomNumber, size);
- if (result < 0 || result != ssize_t(size)) {
- throw jexception(); // TODO: Complete exception details
- }
- ::close(randomData);
- return randomNumber;
+ // TODO: ::rand() is not thread safe, either lock or use rand_r(seed) with a thread-local seed.
+ return ((uint64_t)::rand() << QLS_RAND_SHIFT1) | ((uint64_t)::rand() << QLS_RAND_SHIFT2) | (::rand() & QLS_RAND_MASK);
}
bool JournalFile::isOpen() const {
diff --git a/qpid/cpp/src/qpid/linearstore/journal/jcfg.h b/qpid/cpp/src/qpid/linearstore/journal/jcfg.h
index 82cff99169..1659fe37fa 100644
--- a/qpid/cpp/src/qpid/linearstore/journal/jcfg.h
+++ b/qpid/cpp/src/qpid/linearstore/journal/jcfg.h
@@ -19,6 +19,9 @@
*
*/
+#include <cmath>
+#include <cstdlib>
+
#ifndef QPID_QLS_JRNL_JCFG_H
#define QPID_QLS_JRNL_JCFG_H
@@ -55,4 +58,14 @@
#define QLS_CLEAN /**< If defined, writes QLS_CLEAN_CHAR to all filled areas on disk */
#define QLS_CLEAN_CHAR 0xff /**< Char used to clear empty space on disk */
+namespace qpid {
+namespace linearstore {
+
+ const int QLS_RAND_WIDTH = (int)(::log((RAND_MAX + 1ULL))/::log(2));
+ const int QLS_RAND_SHIFT1 = 64 - QLS_RAND_WIDTH;
+ const int QLS_RAND_SHIFT2 = QLS_RAND_SHIFT1 - QLS_RAND_WIDTH;
+ const int QLS_RAND_MASK = (int)::pow(2, QLS_RAND_SHIFT2) - 1;
+
+}}
+
#endif /* ifndef QPID_QLS_JRNL_JCFG_H */
diff --git a/qpid/cpp/src/qpid/linearstore/journal/utils/file_hdr.c b/qpid/cpp/src/qpid/linearstore/journal/utils/file_hdr.c
index 71a506fedf..f504fb7943 100644
--- a/qpid/cpp/src/qpid/linearstore/journal/utils/file_hdr.c
+++ b/qpid/cpp/src/qpid/linearstore/journal/utils/file_hdr.c
@@ -94,23 +94,6 @@ int is_file_hdr_reset(file_hdr_t* target) {
target->_queue_name_len == 0;
}
-/*
-uint64_t random_64() {
- int randomData = open("/dev/random", O_RDONLY);
- if (randomData < 0) {
- return 0ULL;
- }
- uint64_t randomNumber;
- size_t size = sizeof(randomNumber);
- ssize_t result = read(randomData, (char*)&randomNumber, size);
- if (result != size) {
- randomNumber = 0ULL;
- }
- close(randomData);
- return randomNumber;
-}
-*/
-
int set_time_now(file_hdr_t *fh)
{
struct timespec ts;