Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove codis support #217

Merged
merged 2 commits into from
Apr 12, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 0 additions & 6 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -121,8 +121,6 @@ target_sources(kvrocks PRIVATE
src/redis_pubsub.h
src/redis_sortedint.cc
src/redis_sortedint.h
src/redis_slot.cc
src/redis_slot.h
src/lock_manager.cc
src/rocksdb_crc32c.h
src/config.cc
Expand Down Expand Up @@ -213,8 +211,6 @@ target_sources(kvrocks2redis PRIVATE
src/redis_pubsub.h
src/redis_sortedint.cc
src/redis_sortedint.h
src/redis_slot.cc
src/redis_slot.h
src/replication.cc
src/replication.h
src/lock_manager.cc
Expand Down Expand Up @@ -305,8 +301,6 @@ add_executable(unittest
src/redis_geo.cc
src/redis_sortedint.cc
src/redis_sortedint.h
src/redis_slot.cc
src/redis_slot.h
src/util.cc
src/geohash.cc
src/storage.cc
Expand Down
1 change: 0 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ kvrocks has the following key features:
- Namespace, similar to redis db but use token per namespace
- Replication, async replication using binlog like MySQL
- High Available, supports redis sentinel to failover when master or slave was failed
- Codis Protocol, the user can use the codis proxy and dashboard to manage the kvrocks

> Thanks for @smartlee and the trip.com designer(@范世丽) contributes the kvrocks logo for us

Expand Down
5 changes: 0 additions & 5 deletions kvrocks.conf
Original file line number Diff line number Diff line change
Expand Up @@ -178,11 +178,6 @@ max-backup-to-keep 1
# default: 1 Week
max-backup-keep-hours 168

# Enable the kvrocks to support the codis protocol, if the db enabled the codis mode at first open,
# this option must not be disabled after restarted, and vice versa
# Defalut: no
codis-enabled no

# Ratio of the samples would be recorded when the profiling was enabled.
# we simply use the rand to determine whether to record the sample or not.
#
Expand Down
2 changes: 1 addition & 1 deletion src/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ FINAL_LIBS+= $(GLOG) $(LIBEVENT) $(LIBEVENT_PTHREADS) $(JEMALLOC) $(ROCKSDB)
SHARED_OBJS= compact_filter.o config.o cron.o encoding.o event_listener.o lock_manager.o \
log_collector.o redis_bitmap.o redis_bitmap_string.o redis_cmd.o redis_connection.o redis_db.o \
redis_hash.o redis_list.o redis_metadata.o redis_pubsub.o redis_reply.o \
redis_request.o redis_set.o redis_string.o redis_zset.o redis_geo.o redis_slot.o replication.o \
redis_request.o redis_set.o redis_string.o redis_zset.o redis_geo.o replication.o \
server.o stats.o storage.o task_runner.o util.o geohash.o worker.o redis_sortedint.o \
compaction_checker.o table_properties_collector.o
KVROCKS_OBJS= $(SHARED_OBJS) main.o
Expand Down
68 changes: 0 additions & 68 deletions src/compact_filter.cc
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
#include <utility>
#include <glog/logging.h>
#include "redis_bitmap.h"
#include "redis_slot.h"

namespace Engine {
using rocksdb::Slice;
Expand Down Expand Up @@ -101,71 +100,4 @@ bool SubKeyFilter::Filter(int level,
<< ", result: " << (result ? "deleted" : "reserved");
return result;
}

bool SlotKeyFilter::IsKeyDeleted(const SlotInternalKey &ikey, const Slice &value) const {
std::string metadata_key;

auto db = stor_->GetDB();
const auto cf_handles = stor_->GetCFHandles();
// storage close the would delete the column familiy handler and DB
if (!db || cf_handles->size() < 2) return false;

auto slot_num = GetSlotNumFromKey(ikey.GetKey().ToString());
PutFixed32(&metadata_key, slot_num);
if (cached_key_.empty() || metadata_key != cached_key_) {
std::string bytes;
if (!stor_->IncrDBRefs().IsOK()) { // the db is closing, don't use DB and cf_handles
return false;
}
rocksdb::Status s = db->Get(rocksdb::ReadOptions(), (*cf_handles)[4], metadata_key, &bytes);
stor_->DecrDBRefs();
cached_key_ = std::move(metadata_key);
if (s.ok()) {
cached_metadata_ = std::move(bytes);
} else if (s.IsNotFound()) {
// metadata was deleted
// clear the metadata
cached_metadata_.clear();
return true;
} else {
LOG(ERROR) << "[compact_filter/slotkey] Failed to fetch metadata"
<< ", key: " << ikey.GetKey().ToString()
<< ", err: " << s.ToString();
cached_key_.clear();
cached_metadata_.clear();
return false;
}
}
// the metadata was not found, delete the subkey
if (cached_metadata_.empty()) return true;

SlotMetadata metadata(false);
rocksdb::Status s = metadata.Decode(cached_metadata_);
if (!s.ok()) {
cached_key_.clear();
LOG(ERROR) << "[compact_filter/slotkey] Failed to decode metadata"
<< ", key: " << ikey.GetKey().ToString()
<< ", err: " << s.ToString();
return false;
}
// subkey's version wasn't equal to metadata's version means
// that key was deleted and created new one, so the old subkey
// should be deleted as well.
return ikey.GetVersion() != metadata.version;
}

bool SlotKeyFilter::Filter(int level,
const Slice &key,
const Slice &value,
std::string *new_value,
bool *modified) const {
SlotInternalKey ikey(key);
bool result = IsKeyDeleted(ikey, value);
DLOG(INFO) << "[compact_filter/slotkey] "
<< ", slot_num: " << ikey.GetSlotNum()
<< ", metadata key: " << ikey.GetKey().ToString()
<< ", verison: " << ikey.GetVersion()
<< ", result: " << (result ? "deleted" : "reserved");
return result;
}
} // namespace Engine
36 changes: 0 additions & 36 deletions src/compact_filter.h
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
#include <rocksdb/compaction_filter.h>

#include "redis_metadata.h"
#include "redis_slot.h"
#include "storage.h"

namespace Engine {
Expand Down Expand Up @@ -80,39 +79,4 @@ class PubSubFilterFactory : public rocksdb::CompactionFilterFactory {
return std::unique_ptr<rocksdb::CompactionFilter>(new PubSubFilter());
}
};

class SlotKeyFilter : public rocksdb::CompactionFilter {
public:
explicit SlotKeyFilter(Storage *storage)
: cached_key_(""),
cached_metadata_(""),
stor_(storage) {}

const char *Name() const override { return "SlotKeyFilter"; }
bool IsKeyDeleted(const SlotInternalKey &ikey, const Slice &value) const;
bool Filter(int level, const Slice &key, const Slice &value,
std::string *new_value, bool *modified) const override;

protected:
mutable std::string cached_key_;
mutable std::string cached_metadata_;
Engine::Storage *stor_;
};

class SlotKeyFilterFactory : public rocksdb::CompactionFilterFactory {
public:
explicit SlotKeyFilterFactory(Engine::Storage *storage) {
stor_ = storage;
}

const char *Name() const override { return "SlotKeyFilterFactory"; }
std::unique_ptr<rocksdb::CompactionFilter> CreateCompactionFilter(
const rocksdb::CompactionFilter::Context &context) override {
return std::unique_ptr<rocksdb::CompactionFilter>(
new SlotKeyFilter(stor_));
}

private:
Engine::Storage *stor_ = nullptr;
};
} // namespace Engine
6 changes: 1 addition & 5 deletions src/compaction_checker.cc
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,10 @@
#include <glog/logging.h>
#include "storage.h"

void CompactionChecker::CompactPubsubAndSlotFiles() {
void CompactionChecker::CompactPubsubFiles() {
rocksdb::CompactRangeOptions compact_opts;
compact_opts.change_level = true;
std::vector<std::string> cf_names = {Engine::kPubSubColumnFamilyName};
if (storage_->CodisEnabled()) {
cf_names.emplace_back(Engine::kSlotColumnFamilyName);
cf_names.emplace_back(Engine::kSlotMetadataColumnFamilyName);
}
for (const auto &cf_name : cf_names) {
// the db is closing, don't use DB and cf_handles
if (!storage_->IncrDBRefs().IsOK()) return;
Expand Down
2 changes: 1 addition & 1 deletion src/compaction_checker.h
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ class CompactionChecker {
explicit CompactionChecker(Engine::Storage *storage):storage_(storage) {}
~CompactionChecker() {}
void PickCompactionFiles(const std::string &cf_name);
void CompactPubsubAndSlotFiles();
void CompactPubsubFiles();
private:
Engine::Storage *storage_ = nullptr;
};
7 changes: 0 additions & 7 deletions src/config.cc
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,6 @@ Config::Config() {
{"maxclients", false, new IntField(&maxclients, 10240, 0, INT_MAX)},
{"max-backup-to-keep", false, new IntField(&max_backup_to_keep, 1, 0, 64)},
{"max-backup-keep-hours", false, new IntField(&max_backup_keep_hours, 0, 0, INT_MAX)},
{"codis-enabled", true, new YesNoField(&codis_enabled, false)},
{"master-use-repl-port", false, new YesNoField(&master_use_repl_port, false)},
{"requirepass", false, new StringField(&requirepass, "")},
{"masterauth", false, new StringField(&masterauth, "")},
Expand Down Expand Up @@ -354,9 +353,6 @@ Status Config::finish() {
if (requirepass.empty() && !tokens.empty()) {
return Status(Status::NotOK, "requirepass empty wasn't allowed while the namespace exists");
}
if (codis_enabled && !tokens.empty()) {
return Status(Status::NotOK, "enabled codis wasn't allowed while the namespace exists");
}
if (db_dir.empty()) db_dir = dir + "/db";
if (backup_dir.empty()) backup_dir = dir + "/backup";
if (log_dir.empty()) log_dir = dir;
Expand Down Expand Up @@ -506,9 +502,6 @@ Status Config::AddNamespace(const std::string &ns, const std::string &token) {
if (requirepass.empty()) {
return Status(Status::NotOK, "forbidden to add namespace when requirepass was empty");
}
if (codis_enabled) {
return Status(Status::NotOK, "forbidden to add namespace when codis mode was enabled");
}
auto s = isNamespaceLegal(ns);
if (!s.IsOK()) return s;
if (tokens.find(token) != tokens.end()) {
Expand Down
1 change: 0 additions & 1 deletion src/config.h
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,6 @@ struct Config{
int max_db_size = 0;
int max_replication_mb = 0;
int max_io_mb = 0;
bool codis_enabled = false;
bool master_use_repl_port = false;
std::vector<std::string> binds;
std::string dir;
Expand Down
29 changes: 0 additions & 29 deletions src/redis_bitmap.cc
Original file line number Diff line number Diff line change
Expand Up @@ -134,35 +134,6 @@ rocksdb::Status Bitmap::SetBit(const Slice &user_key, uint32_t offset, bool new_
return storage_->Write(rocksdb::WriteOptions(), &batch);
}

rocksdb::Status Bitmap::MSetBit(const Slice &user_key, const std::vector<BitmapPair> &pairs) {
std::string ns_key, raw_value;
AppendNamespacePrefix(user_key, &ns_key);

LockGuard guard(storage_->GetLockManager(), ns_key);
BitmapMetadata metadata;
rocksdb::Status s = GetMetadata(ns_key, &metadata, &raw_value);
if (!s.ok() && !s.IsNotFound()) return s;

uint32_t cnt = 0;
rocksdb::WriteBatch batch;
WriteBatchLogData log_data(kRedisBitmap);
batch.PutLogData(log_data.Encode());
for (const auto &pair : pairs) {
std::string sub_key;
InternalKey(ns_key, std::to_string(pair.index), metadata.version).Encode(&sub_key);
batch.Put(sub_key, pair.value);

for (size_t j = 0; j < pair.value.size(); j++) {
cnt += kNum2Bits[static_cast<int>(pair.value[j])];
}
}
metadata.size = cnt;
std::string bytes;
metadata.Encode(&bytes);
batch.Put(metadata_cf_handle_, ns_key, bytes);
return storage_->Write(rocksdb::WriteOptions(), &batch);
}

rocksdb::Status Bitmap::BitCount(const Slice &user_key, int start, int stop, uint32_t *cnt) {
*cnt = 0;
std::string ns_key, raw_value;
Expand Down
6 changes: 0 additions & 6 deletions src/redis_bitmap.h
Original file line number Diff line number Diff line change
Expand Up @@ -6,19 +6,13 @@
#include <string>
#include <vector>

typedef struct {
uint32_t index;
Slice value;
} BitmapPair;

namespace Redis {

class Bitmap : public Database {
public:
Bitmap(Engine::Storage *storage, const std::string &ns): Database(storage, ns) {}
rocksdb::Status GetBit(const Slice &user_key, uint32_t offset, bool *bit);
rocksdb::Status SetBit(const Slice &user_key, uint32_t offset, bool new_bit, bool *old_bit);
rocksdb::Status MSetBit(const Slice &user_key, const std::vector<BitmapPair> &pairs);
rocksdb::Status BitCount(const Slice &user_key, int start, int stop, uint32_t *cnt);
rocksdb::Status BitPos(const Slice &user_key, bool bit, int start, int stop, bool stop_given, int *pos);
static bool GetBitFromValueAndOffset(const std::string &value, const uint32_t offset);
Expand Down
Loading