Author: kpvdr
Date: Thu Jan 16 20:46:24 2014
New Revision: 1558913
URL: http://svn.apache.org/r1558913
Log:
QPID-5487: [linearstore] Replace use of /dev/urandom with c random generator
calls
Modified:
qpid/trunk/qpid/cpp/src/qpid/linearstore/ISSUES
qpid/trunk/qpid/cpp/src/qpid/linearstore/MessageStoreImpl.cpp
qpid/trunk/qpid/cpp/src/qpid/linearstore/journal/JournalFile.cpp
qpid/trunk/qpid/cpp/src/qpid/linearstore/journal/jcfg.h
qpid/trunk/qpid/cpp/src/qpid/linearstore/journal/utils/file_hdr.c
Modified: qpid/trunk/qpid/cpp/src/qpid/linearstore/ISSUES
URL:
http://svn.apache.org/viewvc/qpid/trunk/qpid/cpp/src/qpid/linearstore/ISSUES?rev=1558913&r1=1558912&r2=1558913&view=diff
==============================================================================
--- qpid/trunk/qpid/cpp/src/qpid/linearstore/ISSUES (original)
+++ qpid/trunk/qpid/cpp/src/qpid/linearstore/ISSUES Thu Jan 16 20:46:24 2014
@@ -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:
=============
Modified: qpid/trunk/qpid/cpp/src/qpid/linearstore/MessageStoreImpl.cpp
URL:
http://svn.apache.org/viewvc/qpid/trunk/qpid/cpp/src/qpid/linearstore/MessageStoreImpl.cpp?rev=1558913&r1=1558912&r2=1558913&view=diff
==============================================================================
--- qpid/trunk/qpid/cpp/src/qpid/linearstore/MessageStoreImpl.cpp (original)
+++ qpid/trunk/qpid/cpp/src/qpid/linearstore/MessageStoreImpl.cpp Thu Jan 16
20:46:24 2014
@@ -66,7 +66,13 @@ MessageStoreImpl::MessageStoreImpl(qpid:
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_)
{
Modified: qpid/trunk/qpid/cpp/src/qpid/linearstore/journal/JournalFile.cpp
URL:
http://svn.apache.org/viewvc/qpid/trunk/qpid/cpp/src/qpid/linearstore/journal/JournalFile.cpp?rev=1558913&r1=1558912&r2=1558913&view=diff
==============================================================================
--- qpid/trunk/qpid/cpp/src/qpid/linearstore/journal/JournalFile.cpp (original)
+++ qpid/trunk/qpid/cpp/src/qpid/linearstore/journal/JournalFile.cpp Thu Jan 16
20:46:24 2014
@@ -279,18 +279,8 @@ const std::string JournalFile::getFileNa
//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 {
Modified: qpid/trunk/qpid/cpp/src/qpid/linearstore/journal/jcfg.h
URL:
http://svn.apache.org/viewvc/qpid/trunk/qpid/cpp/src/qpid/linearstore/journal/jcfg.h?rev=1558913&r1=1558912&r2=1558913&view=diff
==============================================================================
--- qpid/trunk/qpid/cpp/src/qpid/linearstore/journal/jcfg.h (original)
+++ qpid/trunk/qpid/cpp/src/qpid/linearstore/journal/jcfg.h Thu Jan 16 20:46:24
2014
@@ -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 */
Modified: qpid/trunk/qpid/cpp/src/qpid/linearstore/journal/utils/file_hdr.c
URL:
http://svn.apache.org/viewvc/qpid/trunk/qpid/cpp/src/qpid/linearstore/journal/utils/file_hdr.c?rev=1558913&r1=1558912&r2=1558913&view=diff
==============================================================================
--- qpid/trunk/qpid/cpp/src/qpid/linearstore/journal/utils/file_hdr.c (original)
+++ qpid/trunk/qpid/cpp/src/qpid/linearstore/journal/utils/file_hdr.c Thu Jan
16 20:46:24 2014
@@ -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;
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]