Skip to content

Commit 36a6153

Browse files
committed
api: rocksdb-api in-progress, it is hard to adapt rocksdb column family, stop but keep the partly modified code
1 parent 4ccc3a2 commit 36a6153

File tree

2 files changed

+32
-49
lines changed

2 files changed

+32
-49
lines changed

api/leveldb/leveldb_terark.h

+2-5
Original file line numberDiff line numberDiff line change
@@ -167,14 +167,11 @@ class ColumnFamilyHandleImpl : public ColumnFamilyHandle {
167167
ColumnFamilyHandleImpl(DbImpl* db, std::string const &name, uint32_t id) : db_(db), id_(id), name_(name) {}
168168
ColumnFamilyHandleImpl(const ColumnFamilyHandleImpl &copyfrom) : db_(copyfrom.db_), id_(copyfrom.id_), name_(copyfrom.name_) {}
169169
virtual ~ColumnFamilyHandleImpl() {}
170-
virtual uint32_t GetID() const { return id_; }
171-
170+
size_t GetID() const { return id_; }
172171
std::string const &GetName() const { return name_; }
173-
std::string const GetURI() const { return "table:" + name_; }
174-
175172
private:
176173
DbImpl* db_;
177-
uint32_t id_;
174+
size_t id_;
178175
std::string const name_;
179176
};
180177
#endif

api/leveldb/rocks_terark.cc

+30-44
Original file line numberDiff line numberDiff line change
@@ -27,8 +27,11 @@
2727

2828
#include "leveldb_terark.h"
2929
#include <errno.h>
30-
#include <sys/stat.h>
31-
#include <unistd.h>
30+
#if defined(_WIN32) || defined(_WIN64)
31+
#else
32+
#include <sys/stat.h>
33+
#include <unistd.h>
34+
#endif
3235
#include <sstream>
3336

3437
using leveldb::Cache;
@@ -77,59 +80,42 @@ DB::ListColumnFamilies(
7780
std::vector<std::string> *column_families)
7881
{
7982
std::vector<std::string> cf;
80-
DB *dbptr;
81-
Status status = DB::Open(options, name, &dbptr);
82-
if (!status.ok())
83-
return status;
84-
DbImpl *db = static_cast<DbImpl *>(dbptr);
85-
OperationContext *context = db->GetContext();
86-
WT_SESSION *session = context->GetSession();
87-
WT_CURSOR *c;
88-
int ret = session->open_cursor(session, "metadata:", NULL, NULL, &c);
89-
if (ret != 0)
90-
goto err;
91-
c->set_key(c, "table:");
92-
/* Position on the first table entry */
93-
int cmp;
94-
ret = c->search_near(c, &cmp);
95-
if (ret != 0 || (cmp < 0 && (ret = c->next(c)) != 0))
96-
goto err;
97-
/* Add entries while we are getting "table" URIs. */
98-
for (; ret == 0; ret = c->next(c)) {
99-
const char *key;
100-
if ((ret = c->get_key(c, &key)) != 0)
101-
goto err;
102-
if (strncmp(key, "table:", strlen("table:")) != 0)
103-
break;
104-
printf("List column families: [%d] = %s\n", (int)cf.size(), key);
105-
cf.push_back(std::string(key + strlen("table:")));
83+
fs::path dbdir = fs::path(name) / "TerarkDB";
84+
fs::path metaPath = dbdir / "dbmeta.json";
85+
if (!fs::exists(metaPath)) {
86+
fprintf(stderr, "ERROR: not exists: %s\n", metaPath.string().c_str());
87+
return Status::InvalidArgument("ListColumnFamilies: dbmeta.json is missing", dbdir.string());
10688
}
107-
108-
err: delete db;
109-
/*
110-
* WT_NOTFOUND is not an error: it just means we got to the end of the
111-
* list of tables.
112-
*/
113-
if (ret == 0 || ret == WT_NOTFOUND) {
114-
*column_families = cf;
115-
ret = 0;
89+
try {
90+
terark::db::SchemaConfigPtr sconf = new terark::db::SchemaConfig();
91+
sconf->loadJsonFile(metaPath.string());
92+
column_families->resize(0);
93+
size_t cgNum = sconf->getColgroupNum();
94+
for (size_t i = 0; i < cgNum; ++i) {
95+
const terark::db::Schema& schema = sconf->getColgroupSchema(i);
96+
column_families->push_back(schema.m_name);
97+
}
98+
}
99+
catch (const std::exception& ex) {
100+
return Status::InvalidArgument("ListColumnFamilies: load dbmeta.json failed", dbdir.string());
116101
}
117-
return WiredTigerErrorToStatus(ret);
118102
}
119103

120104
Status
121-
DB::Open(Options const &options, std::string const &name, const std::vector<ColumnFamilyDescriptor> &column_families, std::vector<ColumnFamilyHandle*> *handles, DB**dbptr)
105+
DB::Open(Options const &options,
106+
std::string const &name,
107+
const std::vector<ColumnFamilyDescriptor> &column_families,
108+
std::vector<ColumnFamilyHandle*> *handles,
109+
DB**dbptr)
122110
{
123111
Status status = Open(options, name, dbptr);
124112
if (!status.ok())
125113
return status;
126-
DbImpl *db = static_cast<DbImpl *>(*dbptr);
127-
std::vector<ColumnFamilyHandle*> cfhandles(
128-
column_families.size());
114+
DbImpl *db = static_cast<DbImpl*>(*dbptr);
115+
std::vector<ColumnFamilyHandle*> cfhandles(column_families.size());
129116
for (size_t i = 0; i < column_families.size(); i++) {
130117
printf("Open column families: [%d] = %s\n", (int)i, column_families[i].name.c_str());
131-
cfhandles[i] = new ColumnFamilyHandleImpl(
132-
db, column_families[i].name, (int)i);
118+
cfhandles[i] = new ColumnFamilyHandleImpl(db, column_families[i].name, i);
133119
}
134120
db->SetColumns(*handles = cfhandles);
135121
return Status::OK();

0 commit comments

Comments
 (0)