Skip to content

Commit 19216d6

Browse files
committed
Fix leveldb_api
db_context.hpp : fix gcc warnings
1 parent 234b3de commit 19216d6

File tree

2 files changed

+10
-7
lines changed

2 files changed

+10
-7
lines changed

api/leveldb/leveldb_terark.cc

+9-6
Original file line numberDiff line numberDiff line change
@@ -320,10 +320,11 @@ Status
320320
DbImpl::Put(const WriteOptions& options, const Slice& key, const Slice& value) {
321321
terark::db::DbContext* ctx = GetDbContext();
322322
assert(NULL != ctx);
323+
auto userBuf = ctx->bufs.get();
323324
try {
324325
TRACE_KEY_VAL(key, value);
325-
encodeKeyVal(ctx->userBuf, key, value);
326-
long long recId = ctx->upsertRow(ctx->userBuf);
326+
encodeKeyVal(*userBuf, key, value);
327+
long long recId = ctx->upsertRow(*userBuf);
327328
TERARK_RT_assert(recId >= 0, std::logic_error);
328329
return Status::OK();
329330
}
@@ -358,8 +359,9 @@ void
358359
WriteBatchHandler::Put(const Slice& key, const Slice& value) {
359360
auto opctx = context_;
360361
terark::db::DbContext* ctx = opctx->m_batchWriter.getCtx();
361-
encodeKeyVal(ctx->userBuf, key, value);
362-
opctx->m_batchWriter.upsertRow(ctx->userBuf);
362+
auto userBuf = ctx->bufs.get();
363+
encodeKeyVal(*userBuf, key, value);
364+
opctx->m_batchWriter.upsertRow(*userBuf);
363365
}
364366

365367
static const long g_logBatchRemoveNotFound =
@@ -423,16 +425,17 @@ Status
423425
DbImpl::Get(const ReadOptions& options, const Slice& key, std::string* value) {
424426
terark::db::DbContext* ctx = GetDbContext();
425427
assert(NULL != ctx);
428+
auto userBuf = ctx->bufs.get();
426429
ctx->indexSearchExact(0, key, &ctx->exactMatchRecIdvec);
427430
if (!ctx->exactMatchRecIdvec.empty()) {
428431
auto recId = ctx->exactMatchRecIdvec[0];
429432
try {
430-
ctx->selectOneColgroup(recId, 1, &ctx->userBuf);
433+
ctx->selectOneColgroup(recId, 1, userBuf.get());
431434
// fprintf(stderr
432435
// , "DEBUG: recId=%lld, colgroup[1]={size=%zd, content=%.*s}\n"
433436
// , recId, ctx->userBuf.size(), (int)ctx->userBuf.size(), ctx->userBuf.data());
434437
value->resize(0);
435-
value->append((char*)ctx->userBuf.data(), ctx->userBuf.size());
438+
value->append((char*)userBuf->data(), userBuf->size());
436439
return Status::OK();
437440
}
438441
catch (const std::exception&) {

src/terark/db/db_context.hpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ class DbContextObjCache {
5353
public:
5454
CacheItem get() {
5555
if (pool.empty()) {
56-
return CacheItem(new Wrapper{this});
56+
return CacheItem(new Wrapper{this, {}});
5757
}
5858
else {
5959
return CacheItem(pool.pop_val());

0 commit comments

Comments
 (0)