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 #1533

Closed
wants to merge 6 commits into from
Closed
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
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,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 @@ -591,15 +591,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 @@ -721,6 +715,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 @@ -967,6 +967,12 @@ public HugeGraph graph() {
return this.taskScheduler.graph();
}

@Override
public void init() {
verifyAdminPermission();
this.taskScheduler.init();
}

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

@Override
public void init() {
verifyAdminPermission();
this.authManager.init();
}

@Override
public boolean close() {
verifyAdminPermission();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@
import com.baidu.hugegraph.backend.cache.Cache;
import com.baidu.hugegraph.backend.cache.CacheManager;
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.HugeConfig;
import com.baidu.hugegraph.config.ServerOptions;
import com.baidu.hugegraph.exception.NotSupportException;
Expand Down Expand Up @@ -273,7 +273,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 @@ -34,10 +34,10 @@
import org.apache.tinkerpop.gremlin.util.NumberHelper;

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 @@ -70,7 +70,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 @@ -670,5 +670,45 @@ public long getCounter(HugeType type) {
public boolean isSchemaStore() {
return false;
}

public CassandraSessionPool.Session getSession() {
return super.sessions.session();
}
}

public static class CassandraSystemStore extends CassandraGraphStore {
Copy link
Contributor

Choose a reason for hiding this comment

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

prefer to add CassandraMetaStore extends CassandraStore and it don't need to call registerTableManager(HugeType.VERTEX,...), since tasks data in CassandraSystemStore need to be truncate.


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);
LOG.info("Write down the backend version: {}", driverVersion);
}

@Override
public String storedVersion() {
this.checkOpened();
CassandraSessionPool.Session session = this.getSession();
return this.meta.readVersion(session);
Copy link
Contributor

Choose a reason for hiding this comment

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

seems server-info can also be stored into meta table

}

@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;

public class CassandraStoreProvider extends AbstractBackendStoreProvider {

Expand All @@ -40,13 +41,18 @@ protected BackendStore newGraphStore(String store) {
return new CassandraGraphStore(this, this.keyspace(), store);
}

@Override
protected BackendStore newSystemStore(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 @@ -62,7 +68,8 @@ public String version() {
* [1.8] #746: support userdata for indexlabel
* [1.9] #295: support ttl for vertex and edge
* [1.10] #1333: support read frequency for property key
* [1.11] #1533: add meta table in system store
*/
return "1.10";
return "1.11";
}
}
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
Original file line number Diff line number Diff line change
Expand Up @@ -35,9 +35,8 @@
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.ConfigOption;
import com.baidu.hugegraph.config.TypedOption;
import com.baidu.hugegraph.rpc.RpcServiceConfig4Client;
import com.baidu.hugegraph.rpc.RpcServiceConfig4Server;
Expand Down Expand Up @@ -133,8 +132,7 @@ public interface HugeGraph extends Graph {

public String name();
public String backend();
public String backendVersion();
public BackendStoreSystemInfo backendStoreSystemInfo();
public BackendStoreInfo backendStoreInfo();
public BackendFeatures backendStoreFeatures();

public GraphMode mode();
Expand All @@ -154,6 +152,8 @@ public interface HugeGraph extends Graph {
public void clearBackend();
public void truncateBackend();

public void initSystemInfo();

public void createSnapshot();
public 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 @@ -67,6 +68,7 @@ public interface HugeGraphParams {

public ServerInfoManager serverManager();

public LocalCounter counter();
public AbstractSerializer serializer();
public Analyzer analyzer();
public RateLimiter writeRateLimiter();
Expand Down
Loading