1
0
Fork 0

add buffer() to RocksDBValue for data retrieval

This commit is contained in:
Jan Christoph Uhde 2017-03-31 15:41:27 +02:00
parent c038815941
commit 772a7a32da
6 changed files with 17 additions and 17 deletions

View File

@ -105,7 +105,7 @@ arangodb::Result RocksDBCollection::persistProperties() {
RocksDBKey key(RocksDBKey::Collection(_logicalCollection->vocbase()->id(), _objectId));
RocksDBValue value(RocksDBValue::Document(infoBuilder.slice()));
res = globalRocksDBPut(key.string(), *value.string());
res = globalRocksDBPut(key.string(), value.string());
} catch (arangodb::basics::Exception const& ex) {
res.reset(ex.code());
@ -810,7 +810,7 @@ int RocksDBCollection::insertDocument(arangodb::transaction::Methods* trx,
<< "INSERT DOCUMENT. COLLECTION '" << _logicalCollection->name()
<< "', OBJECTID: " << _objectId << ", REVISIONID: " << revisionId;
rocksdb::Status status = rtrx->Put(key.string(), *value.string());
rocksdb::Status status = rtrx->Put(key.string(), value.string());
if (!status.ok()) {
auto converted =
rocksutils::convertStatus(status, rocksutils::StatusHint::document);

View File

@ -245,14 +245,14 @@ void RocksDBEngine::getCollectionInfo(TRI_vocbase_t* vocbase, TRI_voc_cid_t cid,
auto key = RocksDBKey::Collection(vocbase->id(), cid);
auto value = RocksDBValue::Empty(RocksDBEntryType::Collection);
rocksdb::ReadOptions options;
rocksdb::Status res = _db->Get(options, key.string(), value.string());
rocksdb::Status res = _db->Get(options, key.string(), value.buffer());
auto result = rocksutils::convertStatus(res);
if (result.errorNumber() != TRI_ERROR_NO_ERROR) {
THROW_ARANGO_EXCEPTION(result.errorNumber());
}
builder.add("parameters", VPackSlice(value.string()->data()));
builder.add("parameters", VPackSlice(value.buffer()->data()));
if (includeIndexes) {
// dump index information
@ -386,7 +386,7 @@ int RocksDBEngine::writeCreateDatabaseMarker(TRI_voc_tick_t id,
auto value = RocksDBValue::Database(slice);
rocksdb::WriteOptions options; // TODO: check which options would make sense
rocksdb::Status res = _db->Put(options, key.string(), *value.string());
rocksdb::Status res = _db->Put(options, key.string(), value.string());
auto result = rocksutils::convertStatus(res);
return result.errorNumber();
}
@ -398,7 +398,7 @@ int RocksDBEngine::writeCreateCollectionMarker(TRI_voc_tick_t databaseId,
auto value = RocksDBValue::Collection(slice);
rocksdb::WriteOptions options; // TODO: check which options would make sense
rocksdb::Status res = _db->Put(options, key.string(), *value.string());
rocksdb::Status res = _db->Put(options, key.string(), value.string());
auto result = rocksutils::convertStatus(res);
return result.errorNumber();
}
@ -499,7 +499,7 @@ void RocksDBEngine::createIndex(TRI_vocbase_t* vocbase,
auto key = RocksDBKey::Index(vocbase->id(), collectionId, indexId);
auto value = RocksDBValue::Index(data);
rocksdb::Status res = _db->Put(options, key.string(), *value.string());
rocksdb::Status res = _db->Put(options, key.string(), value.string());
auto result = rocksutils::convertStatus(res);
if (!result.ok()) {
THROW_ARANGO_EXCEPTION(result.errorNumber());

View File

@ -216,7 +216,8 @@ RocksDBToken RocksDBPrimaryIndex::lookupKey(transaction::Methods* trx,
auto f = _cache->find(key.string().data(),
static_cast<uint32_t>(key.string().size()));
if (f.found()) {
value.string()->append(reinterpret_cast<char const*>(f.value()->value()),
f.value();
value.buffer()->append(reinterpret_cast<char const*>(f.value()->value()),
static_cast<size_t>(f.value()->valueSize));
return RocksDBToken(RocksDBValue::revisionId(value));
}
@ -227,7 +228,7 @@ RocksDBToken RocksDBPrimaryIndex::lookupKey(transaction::Methods* trx,
rocksdb::Transaction* rtrx = state->rocksTransaction();
auto options = state->readOptions();
auto status = rtrx->Get(options, key.string(), value.string());
auto status = rtrx->Get(options, key.string(), value.buffer());
if (!status.ok()) {
return RocksDBToken();
}
@ -236,7 +237,7 @@ RocksDBToken RocksDBPrimaryIndex::lookupKey(transaction::Methods* trx,
// write entry back to cache
auto entry = cache::CachedValue::construct(
key.string().data(), static_cast<uint32_t>(key.string().size()),
value.string()->data(), static_cast<uint64_t>(value.string()->size()));
value.buffer()->data(), static_cast<uint64_t>(value.buffer()->size()));
bool cached = _cache->insert(entry);
if (!cached) {
delete entry;
@ -257,7 +258,7 @@ RocksDBToken RocksDBPrimaryIndex::lookupKey(
rocksdb::Transaction* rtrx = state->rocksTransaction();
auto options = state->readOptions();
auto status = rtrx->Get(options, key.string(), value.string());
auto status = rtrx->Get(options, key.string(), value.buffer());
if (!status.ok()) {
return RocksDBToken();
}
@ -291,7 +292,7 @@ int RocksDBPrimaryIndex::insert(transaction::Methods* trx,
}
}
auto status = rtrx->Put(key.string(), *value.string());
auto status = rtrx->Put(key.string(), value.string());
if (!status.ok()) {
auto converted =
rocksutils::convertStatus(status, rocksutils::StatusHint::index);

View File

@ -503,14 +503,14 @@ int RocksDBVPackIndex::insert(transaction::Methods* trx,
if (_unique) {
RocksDBValue existing =
RocksDBValue::Empty(RocksDBEntryType::UniqueIndexValue);
auto status = rtrx->Get(options, key.string(), existing.string());
auto status = rtrx->Get(options, key.string(), existing.buffer());
if (!status.IsNotFound()) {
res = TRI_ERROR_ARANGO_UNIQUE_CONSTRAINT_VIOLATED;
}
}
if (res == TRI_ERROR_NO_ERROR) {
auto s = rtrx->Put(key.string(), *value.string());
auto s = rtrx->Put(key.string(), value.string());
auto status = rocksutils::convertStatus(s, rocksutils::StatusHint::index);
if (!status.ok()) {

View File

@ -105,8 +105,6 @@ VPackSlice RocksDBValue::data(std::string const& s) {
return data(s.data(), s.size());
}
std::string* RocksDBValue::string() { return &_buffer; }
RocksDBValue::RocksDBValue(RocksDBEntryType type) : _type(type), _buffer() {}
RocksDBValue::RocksDBValue(RocksDBEntryType type, uint64_t data)

View File

@ -94,7 +94,8 @@ class RocksDBValue {
//////////////////////////////////////////////////////////////////////////////
/// @brief Returns a reference to the underlying string buffer.
//////////////////////////////////////////////////////////////////////////////
std::string* string();
std::string const& string() { return _buffer; } // to be used with put
std::string* buffer() { return &_buffer; } // to be used with get
private:
RocksDBValue();