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

Add system schema store #1891

Merged
merged 7 commits into from
Jun 2, 2022
Merged
Show file tree
Hide file tree
Changes from 5 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
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@
import com.baidu.hugegraph.backend.id.IdGenerator;
import com.baidu.hugegraph.backend.query.Query;
import com.baidu.hugegraph.backend.store.BackendFeatures;
import com.baidu.hugegraph.backend.store.BackendStoreSystemInfo;
import com.baidu.hugegraph.backend.store.BackendStoreInfo;
import com.baidu.hugegraph.backend.store.raft.RaftGroupManager;
import com.baidu.hugegraph.config.AuthOptions;
import com.baidu.hugegraph.config.HugeConfig;
Expand Down Expand Up @@ -604,15 +604,9 @@ public String backend() {
}

@Override
public String backendVersion() {
this.verifyAnyPermission();
return this.hugegraph.backendVersion();
}

@Override
public BackendStoreSystemInfo backendStoreSystemInfo() {
public BackendStoreInfo backendStoreInfo() {
this.verifyAdminPermission();
return this.hugegraph.backendStoreSystemInfo();
return this.hugegraph.backendStoreInfo();
}

@Override
Expand Down Expand Up @@ -734,6 +728,12 @@ public void truncateBackend() {
}
}

@Override
public void initSystemInfo() {
this.verifyAdminPermission();
this.hugegraph.initSystemInfo();
}

@Override
public void createSnapshot() {
this.verifyPermission(HugePermission.WRITE, ResourceType.STATUS);
Expand Down Expand Up @@ -998,6 +998,12 @@ public HugeGraph graph() {
return this.taskScheduler.graph();
}

@Override
public void init() {
verifyAdminPermission();
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this.verifyAdminPermission()

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this method doesn't use this, the code is in inner class TaskSchedulerProxy

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

get it

this.taskScheduler.init();
}

@Override
public int pendingTasks() {
verifyTaskPermission(HugePermission.READ);
Expand Down Expand Up @@ -1161,6 +1167,12 @@ private String currentUsername() {
return null;
}

@Override
public void init() {
verifyAdminPermission();
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ditto

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this is inner class AuthManagerProxy, so can't use this.

this.authManager.init();
}

@Override
public boolean close() {
verifyAdminPermission();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@
import com.baidu.hugegraph.backend.cache.CacheManager;
import com.baidu.hugegraph.backend.id.Id;
import com.baidu.hugegraph.backend.id.IdGenerator;
import com.baidu.hugegraph.backend.store.BackendStoreSystemInfo;
import com.baidu.hugegraph.backend.store.BackendStoreInfo;
import com.baidu.hugegraph.config.CoreOptions;
import com.baidu.hugegraph.config.HugeConfig;
import com.baidu.hugegraph.config.ServerOptions;
Expand Down Expand Up @@ -393,7 +393,7 @@ private void checkBackendVersionOrExit(HugeConfig config) {
}
}
}
BackendStoreSystemInfo info = hugegraph.backendStoreSystemInfo();
BackendStoreInfo info = hugegraph.backendStoreInfo();
if (!info.exists()) {
throw new BackendException(
"The backend store of '%s' has not been initialized",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,10 +38,10 @@
import org.slf4j.Logger;

import com.baidu.hugegraph.backend.store.BackendMetrics;
import com.baidu.hugegraph.backend.store.BackendStoreProvider;
import com.baidu.hugegraph.backend.store.BackendTable;
import com.baidu.hugegraph.backend.store.cassandra.CassandraTables.Edge;
import com.baidu.hugegraph.backend.store.cassandra.CassandraTables.Vertex;
import com.baidu.hugegraph.config.CoreOptions;
import com.baidu.hugegraph.config.HugeConfig;
import com.baidu.hugegraph.testutil.Whitebox;
import com.baidu.hugegraph.util.E;
Expand Down Expand Up @@ -77,7 +77,7 @@ public CassandraMetrics(HugeConfig conf,
assert this.username != null && this.password != null;

this.keyspace = keyspace;
String g = conf.get(CoreOptions.STORE_GRAPH);
String g = BackendStoreProvider.GRAPH_STORE;
String v = BackendTable.joinTableName(g, Vertex.TABLE);
String oe = BackendTable.joinTableName(g, "o" + Edge.TABLE_SUFFIX);
String ie = BackendTable.joinTableName(g, "i" + Edge.TABLE_SUFFIX);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -782,5 +782,45 @@ public void removeOlapTable(Id id) {
table.dropTable(this.session());
this.unregisterTableManager(name);
}

public CassandraSessionPool.Session getSession() {
zyxxoo marked this conversation as resolved.
Show resolved Hide resolved
return super.sessions.session();
}
}

public static class CassandraSystemStore extends CassandraGraphStore {

private final CassandraTables.Meta meta;

public CassandraSystemStore(BackendStoreProvider provider,
String keyspace, String store) {
super(provider, keyspace, store);

this.meta = new CassandraTables.Meta();
}

@Override
public void init() {
super.init();
this.checkOpened();
CassandraSessionPool.Session session = this.getSession();
String driverVersion = this.provider().driverVersion();
this.meta.writeVersion(session, driverVersion);
zyxxoo marked this conversation as resolved.
Show resolved Hide resolved
LOG.info("Write down the backend version: {}", driverVersion);
}

@Override
public String storedVersion() {
this.checkOpened();
CassandraSessionPool.Session session = this.getSession();
return this.meta.readVersion(session);
zyxxoo marked this conversation as resolved.
Show resolved Hide resolved
}

@Override
protected Collection<CassandraTable> tables() {
List<CassandraTable> tables = new ArrayList<>(super.tables());
tables.add(this.meta);
return tables;
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
import com.baidu.hugegraph.backend.store.BackendStore;
import com.baidu.hugegraph.backend.store.cassandra.CassandraStore.CassandraGraphStore;
import com.baidu.hugegraph.backend.store.cassandra.CassandraStore.CassandraSchemaStore;
import com.baidu.hugegraph.backend.store.cassandra.CassandraStore.CassandraSystemStore;
import com.baidu.hugegraph.config.HugeConfig;

public class CassandraStoreProvider extends AbstractBackendStoreProvider {
Expand All @@ -41,13 +42,18 @@ protected BackendStore newGraphStore(HugeConfig config, String store) {
return new CassandraGraphStore(this, this.keyspace(), store);
}

@Override
protected BackendStore newSystemStore(HugeConfig config, String store) {
return new CassandraSystemStore(this, this.keyspace(), store);
}

@Override
public String type() {
return "cassandra";
}

@Override
public String version() {
public String driverVersion() {
/*
* Versions history:
* [1.0] HugeGraph-1328: supports backend table version checking
Expand All @@ -64,6 +70,7 @@ public String version() {
* [1.9] #295: support ttl for vertex and edge
* [1.10] #1333: support read frequency for property key
* [1.11] #1506: support olap properties
* [1.11] #1533: add meta table in system store
*/
return "1.11";
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,48 @@ public class CassandraTables {

private static final long COMMIT_DELETE_BATCH = Query.COMMIT_BATCH;

public static class Meta extends CassandraTable {

public static final String TABLE = HugeType.META.string();

public Meta() {
super(TABLE);
}

@Override
public void init(CassandraSessionPool.Session session) {
ImmutableMap<HugeKeys, DataType> pkeys = ImmutableMap.of(
HugeKeys.NAME, DataType.text()
);
ImmutableMap<HugeKeys, DataType> ckeys = ImmutableMap.of();
ImmutableMap<HugeKeys, DataType> columns = ImmutableMap.of(
HugeKeys.VALUE, DataType.text()
);

this.createTable(session, pkeys, ckeys, columns);
}

public void writeVersion(CassandraSessionPool.Session session,
String version) {
Insert insert = QueryBuilder.insertInto(TABLE);
insert.value(formatKey(HugeKeys.NAME), formatKey(HugeKeys.VERSION));
insert.value(formatKey(HugeKeys.VALUE), version);
session.execute(insert);
}

public String readVersion(CassandraSessionPool.Session session) {
Clause where = formatEQ(HugeKeys.NAME, formatKey(HugeKeys.VERSION));
Select select = QueryBuilder.select(formatKey(HugeKeys.VALUE))
.from(TABLE);
select.where(where);
Row row = session.execute(select).one();
if (row == null) {
return null;
}
return row.getString(formatKey(HugeKeys.VALUE));
}
}

public static class Counters extends CassandraTable {

public static final String TABLE = HugeType.COUNTER.string();
Expand Down
11 changes: 6 additions & 5 deletions hugegraph-core/src/main/java/com/baidu/hugegraph/HugeGraph.java
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@
import com.baidu.hugegraph.backend.id.Id;
import com.baidu.hugegraph.backend.query.Query;
import com.baidu.hugegraph.backend.store.BackendFeatures;
import com.baidu.hugegraph.backend.store.BackendStoreSystemInfo;
import com.baidu.hugegraph.backend.store.BackendStoreInfo;
import com.baidu.hugegraph.backend.store.raft.RaftGroupManager;
import com.baidu.hugegraph.config.HugeConfig;
import com.baidu.hugegraph.config.TypedOption;
Expand Down Expand Up @@ -179,18 +179,17 @@ public interface HugeGraph extends Graph {

String backend();

String backendVersion();

BackendStoreSystemInfo backendStoreSystemInfo();

BackendFeatures backendStoreFeatures();

BackendStoreInfo backendStoreInfo();

GraphMode mode();

void mode(GraphMode mode);

GraphReadMode readMode();


zyxxoo marked this conversation as resolved.
Show resolved Hide resolved
void readMode(GraphReadMode readMode);

void waitReady(RpcServer rpcServer);
Expand All @@ -209,6 +208,8 @@ public interface HugeGraph extends Graph {

void truncateBackend();

void initSystemInfo();

void createSnapshot();

void resumeSnapshot();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
package com.baidu.hugegraph;

import com.baidu.hugegraph.analyzer.Analyzer;
import com.baidu.hugegraph.backend.LocalCounter;
import com.baidu.hugegraph.backend.serializer.AbstractSerializer;
import com.baidu.hugegraph.backend.store.BackendFeatures;
import com.baidu.hugegraph.backend.store.BackendStore;
Expand Down Expand Up @@ -80,6 +81,8 @@ public interface HugeGraphParams {

ServerInfoManager serverManager();

LocalCounter counter();

AbstractSerializer serializer();

Analyzer analyzer();
Expand Down
Loading