}
StoredValue *EventuallyPersistentStore::fetchValidValue(RCPtr<VBucket> &vb,
- const std::string &key,
+ const const_sized_buffer key,
int bucket_num,
bool wantDeleted,
bool trackReference,
ENGINE_ERROR_CODE EventuallyPersistentStore::addTempItemForBgFetch(
LockHolder &lock,
int bucket_num,
- const std::string &key,
+ const const_sized_buffer key,
RCPtr<VBucket> &vb,
const void *cookie,
bool metadataOnly,
uint64_t(fetchedItems.size()), vbId, gethrtime()/1000000);
}
-void EventuallyPersistentStore::bgFetch(const std::string &key,
+void EventuallyPersistentStore::bgFetch(const const_sized_buffer key,
uint16_t vbucket,
const void *cookie,
bool isMeta) {
}
}
-GetValue EventuallyPersistentStore::getInternal(const std::string &key,
+GetValue EventuallyPersistentStore::getInternal(const const_sized_buffer key,
uint16_t vbucket,
const void *cookie,
vbucket_state_t allowedState,
*
* @return a GetValue representing the result of the request
*/
- GetValue get(const std::string &key, uint16_t vbucket,
+ GetValue get(const const_sized_buffer key, uint16_t vbucket,
const void *cookie, get_options_t options) {
return getInternal(key, vbucket, cookie, vbucket_state_active,
options);
*
* @return a GetValue representing the result of the request
*/
- GetValue getReplica(const std::string &key, uint16_t vbucket,
+ GetValue getReplica(const const_sized_buffer key, uint16_t vbucket,
const void *cookie,
get_options_t options = static_cast<get_options_t>(
QUEUE_BG_FETCH |
* @param type whether the fetch is for a non-resident value or metadata of
* a (possibly) deleted item
*/
- void bgFetch(const std::string &key,
+ void bgFetch(const const_sized_buffer key,
uint16_t vbucket,
const void *cookie,
bool isMeta = false);
PersistenceCallback* flushOneDelOrSet(const queued_item &qi,
RCPtr<VBucket> &vb);
- StoredValue *fetchValidValue(RCPtr<VBucket> &vb, const std::string &key,
+ StoredValue *fetchValidValue(RCPtr<VBucket> &vb, const const_sized_buffer key,
int bucket_num, bool wantsDeleted=false,
bool trackReference=true, bool queueExpired=true);
- GetValue getInternal(const std::string &key, uint16_t vbucket,
+ GetValue getInternal(const const_sized_buffer key, uint16_t vbucket,
const void *cookie,
vbucket_state_t allowedState,
get_options_t options = TRACK_REFERENCE);
ENGINE_ERROR_CODE addTempItemForBgFetch(LockHolder &lock, int bucket_num,
- const std::string &key, RCPtr<VBucket> &vb,
+ const const_sized_buffer key, RCPtr<VBucket> &vb,
const void *cookie, bool metadataOnly,
bool isReplication = false);
get_options_t options)
{
BlockTimer timer(&stats.getCmdHisto);
- std::string k(static_cast<const char*>(key), nkey);
+ const const_sized_buffer k(static_cast<const char*>(key), nkey);
GetValue gv(epstore->get(k, vbucket, cookie, options));
ENGINE_ERROR_CODE ret = gv.getStatus();
}
add_type_t HashTable::unlocked_addTempItem(int &bucket_num,
- const std::string &key,
+ const const_sized_buffer key,
item_eviction_policy_t policy,
bool isReplication) {
uint8_t ext_meta[1];
uint8_t ext_len = EXT_META_LEN;
*(ext_meta) = PROTOCOL_BINARY_RAW_BYTES;
- Item itm(key.c_str(), key.length(), /*flags*/0, /*exp*/0, /*data*/NULL,
+ Item itm(key.data(), key.size(), /*flags*/0, /*exp*/0, /*data*/NULL,
/*size*/0, ext_meta, ext_len, 0, StoredValue::state_temp_init);
// if a temp item for a possibly deleted, set it non-resident by resetting
#include "item_pager.h"
#include "utility.h"
+#include "daemon/buffer.h"
#include <platform/cb_malloc.h>
// Forward declaration for StoredValue
* @param k the key we're checking
* @return true if this item's key is equal to k
*/
- bool hasKey(const std::string &k) const {
- return k.length() == getKeyLen()
+ bool hasKey(const const_sized_buffer k) const {
+ return k.size() == getKeyLen()
&& (std::memcmp(k.data(), getKeyBytes(), getKeyLen()) == 0);
}
* @param key the key to find
* @return a pointer to a StoredValue -- NULL if not found
*/
- StoredValue *find(const std::string &key, bool trackReference=true) {
+ StoredValue *find(const const_sized_buffer key, bool trackReference=true) {
if (!isActive()) {
throw std::logic_error("HashTable::find: Cannot call on a "
"non-active object");
* @return an indication of what happened
*/
add_type_t unlocked_addTempItem(int &bucket_num,
- const std::string &key,
+ const const_sized_buffer key,
item_eviction_policy_t policy,
bool isReplication = false);
* @param policy item eviction policy
* @return an indicator of what the deletion did
*/
- mutation_type_t softDelete(const std::string &key, uint64_t cas,
+ mutation_type_t softDelete(const const_sized_buffer key, uint64_t cas,
item_eviction_policy_t policy = VALUE_ONLY) {
if (!isActive()) {
throw std::logic_error("HashTable::softDelete: Cannot call on a "
*
* @return a pointer to a StoredValue -- NULL if not found
*/
- StoredValue *unlocked_find(const std::string &key, int bucket_num,
+ StoredValue *unlocked_find(const const_sized_buffer key, int bucket_num,
bool wantsDeleted=false, bool trackReference=true) {
StoredValue *v = values[bucket_num];
while (v) {
return getLockedBucket(hash(s.data(), s.size()), bucket);
}
+ inline LockHolder getLockedBucket(const const_sized_buffer key, int *bucket) {
+ return getLockedBucket(hash(key.data(), key.size()), bucket);
+ }
+
/**
* Delete a key from the cache without trying to lock the cache first
* (Please note that you <b>MUST</b> acquire the mutex before calling
* @param bucket_num the bucket to look in (must already be locked)
* @return true if an object was deleted, false otherwise
*/
- bool unlocked_del(const std::string &key, int bucket_num) {
+ bool unlocked_del(const const_sized_buffer key, int bucket_num) {
if (!isActive()) {
throw std::logic_error("HashTable::unlocked_del: Cannot call on a "
"non-active object");
* @param key the key to delete
* @return true if the item existed before this call
*/
- bool del(const std::string &key) {
+ bool del(const const_sized_buffer key) {
int bucket_num(0);
LockHolder lh = getLockedBucket(key, &bucket_num);
return unlocked_del(key, bucket_num);
#include <string>
#include "atomic.h"
#include "kvstore.h"
+#include "daemon/buffer.h"
enum task_state_t {
TASK_RUNNING,
*/
class SingleBGFetcherTask : public GlobalTask {
public:
- SingleBGFetcherTask(EventuallyPersistentEngine *e, const std::string &k,
+ SingleBGFetcherTask(EventuallyPersistentEngine *e, const const_sized_buffer k,
uint16_t vbid, const void *c, bool isMeta,
int sleeptime = 0, bool completeBeforeShutdown = false)
: GlobalTask(e, TaskId::SingleBGFetcherTask, sleeptime, completeBeforeShutdown),
- key(k),
+ key(k.data(), k.size()),
vbucket(vbid),
cookie(c),
metaFetch(isMeta),
}
}
-size_t VBucket::queueBGFetchItem(const std::string &key,
+size_t VBucket::queueBGFetchItem(const const_sized_buffer key,
VBucketBGFetchItem *fetch,
BgFetcher *bgFetcher) {
LockHolder lh(pendingBGFetchesLock);
- vb_bgfetch_item_ctx_t& bgfetch_itm_ctx = pendingBGFetches[key];
+ vb_bgfetch_item_ctx_t& bgfetch_itm_ctx =
+ pendingBGFetches[std::string(key.data(), key.size())];
if (bgfetch_itm_ctx.bgfetched_list.empty()) {
bgfetch_itm_ctx.isMetaOnly = true;
}
}
-bool VBucket::maybeKeyExistsInFilter(const std::string &key) {
+bool VBucket::maybeKeyExistsInFilter(const const_sized_buffer key) {
LockHolder lh(bfMutex);
if (bFilter) {
- return bFilter->maybeKeyExists(key.c_str(), key.length());
+ return bFilter->maybeKeyExists(key.data(), key.size());
} else {
// If filter doesn't exist, allow the BgFetch to go through.
return true;
* Returns the number of pending background fetches after
* adding the specified item.
**/
- size_t queueBGFetchItem(const std::string &key, VBucketBGFetchItem *fetch,
+ size_t queueBGFetchItem(const const_sized_buffer key,
+ VBucketBGFetchItem *fetch,
BgFetcher *bgFetcher);
bool hasPendingBGFetchItems(void) {
void createFilter(size_t key_count, double probability);
void initTempFilter(size_t key_count, double probability);
void addToFilter(const std::string &key);
- bool maybeKeyExistsInFilter(const std::string &key);
+ bool maybeKeyExistsInFilter(const const_sized_buffer key);
bool isTempFilterAvailable();
void addToTempFilter(const std::string &key);
void swapFilter();
void rollback_after_deletion_test(bool flush_before_rollback) {
// Setup: Store an item then flush the vBucket (creating a checkpoint);
// then delete the item and create a second checkpoint.
- auto item_v1 = store_item(vbid, "a", "1");
+ std::string a("a");
+ auto item_v1 = store_item(vbid, a, "1");
ASSERT_EQ(initial_seqno + 1, item_v1.getBySeqno());
ASSERT_EQ(1, store->flushVBucket(vbid));
uint64_t cas = item_v1.getCas();
mutation_descr_t mut_info;
ASSERT_EQ(ENGINE_SUCCESS,
- store->deleteItem("a", &cas, vbid, /*cookie*/nullptr,
+ store->deleteItem(a, &cas, vbid, /*cookie*/nullptr,
/*force*/false, /*itemMeta*/nullptr,
&mut_info));
if (flush_before_rollback) {
}
// Sanity-check - item should no longer exist.
EXPECT_EQ(ENGINE_KEY_ENOENT,
- store->get("a", vbid, nullptr, {}).getStatus());
+ store->get(a, vbid, nullptr, {}).getStatus());
// Test - rollback to seqno of item_v1 and verify that the previous value
// of the item has been restored.
store->setVBucketState(vbid, vbucket_state_replica, false);
ASSERT_EQ(ENGINE_SUCCESS, store->rollback(vbid, item_v1.getBySeqno()));
- auto result = store->public_getInternal("a", vbid, /*cookie*/nullptr,
+ auto result = store->public_getInternal(a, vbid, /*cookie*/nullptr,
vbucket_state_replica, {});
ASSERT_EQ(ENGINE_SUCCESS, result.getStatus());
EXPECT_EQ(item_v1, *result.getValue())
void rollback_after_mutation_test(bool flush_before_rollback) {
// Setup: Store an item then flush the vBucket (creating a checkpoint);
// then update the item with a new value and create a second checkpoint.
- auto item_v1 = store_item(vbid, "a", "old");
+ std::string a("a");
+ auto item_v1 = store_item(vbid, a, "old");
ASSERT_EQ(initial_seqno + 1, item_v1.getBySeqno());
ASSERT_EQ(1, store->flushVBucket(vbid));
- auto item2 = store_item(vbid, "a", "new");
+ auto item2 = store_item(vbid, a, "new");
ASSERT_EQ(initial_seqno + 2, item2.getBySeqno());
- store_item(vbid, "key", "meh");
+ std::string key("key");
+ store_item(vbid, key, "meh");
if (flush_before_rollback) {
EXPECT_EQ(2, store->flushVBucket(vbid));
// a should have the value of 'old'
{
- auto result = store->get("a", vbid, nullptr, {});
+ auto result = store->get(a, vbid, nullptr, {});
ASSERT_EQ(ENGINE_SUCCESS, result.getStatus());
EXPECT_EQ(item_v1, *result.getValue())
<< "Fetched item after rollback should match item_v1";
// key should be gone
{
- auto result = store->get("key", vbid, nullptr, {});
+ auto result = store->get(key, vbid, nullptr, {});
EXPECT_EQ(ENGINE_KEY_ENOENT, result.getStatus())
<< "A key set after the rollback point was found";
}
// These keys should be gone after the rollback
for (int i = 0; i < 3; i++) {
std::string key = "rollback-cp-" + std::to_string(i);
- auto result = store->get(key.c_str(), vbid, nullptr, {});
+ auto result = store->get(key, vbid, nullptr, {});
EXPECT_EQ(ENGINE_KEY_ENOENT, result.getStatus())
<< "A key set after the rollback point was found";
}
// These keys should be gone after the rollback
for (int i = 0; i < 3; i++) {
std::string key = "anotherkey_" + std::to_string(i);
- auto result = store->get(key.c_str(), vbid, nullptr, {});
+ auto result = store->get(key, vbid, nullptr, {});
EXPECT_EQ(ENGINE_KEY_ENOENT, result.getStatus())
<< "A key set after the rollback point was found";
}
std::string key("key");
Item item(key.data(), key.length(), 0, 0, "deleted", strlen("deleted"));
ASSERT_EQ(WAS_CLEAN, ht.set(item));
- ASSERT_EQ(WAS_DIRTY, ht.softDelete("key", 0));
+ ASSERT_EQ(WAS_DIRTY, ht.softDelete(key, 0));
// Attempt to perform a set on a deleted key with a CAS.
Item replacement(key.data(), key.length(), 0, 0, "value", strlen("value"));