use of com.baidu.hugegraph.backend.store.BackendStoreSystemInfo in project incubator-hugegraph by apache.
the class GraphManager method checkBackendVersionOrExit.
private void checkBackendVersionOrExit(HugeConfig config) {
for (String graph : this.graphs()) {
// TODO: close tx from main thread
HugeGraph hugegraph = this.graph(graph);
if (!hugegraph.backendStoreFeatures().supportsPersistence()) {
hugegraph.initBackend();
if (this.requireAuthentication()) {
String token = config.get(ServerOptions.AUTH_ADMIN_TOKEN);
try {
this.authenticator.initAdminUser(token);
} catch (Exception e) {
throw new BackendException("The backend store of '%s' can't " + "initialize admin user", hugegraph.name());
}
}
}
BackendStoreSystemInfo info = hugegraph.backendStoreSystemInfo();
if (!info.exists()) {
throw new BackendException("The backend store of '%s' has not been initialized", hugegraph.name());
}
if (!info.checkVersion()) {
throw new BackendException("The backend store version is inconsistent");
}
}
}
use of com.baidu.hugegraph.backend.store.BackendStoreSystemInfo in project incubator-hugegraph by apache.
the class BackendStoreSystemInfoTest method testBackendStoreSystemInfoIllegalStateException.
@Test
public void testBackendStoreSystemInfoIllegalStateException() {
HugeGraph graph = Mockito.mock(HugeGraph.class);
SchemaTransaction stx = Mockito.mock(SchemaTransaction.class);
Mockito.when(stx.getPropertyKey(PK_BACKEND_INFO)).thenThrow(new IllegalStateException("Should not exist schema " + "with same name '~backend_info'"));
Mockito.when(stx.graph()).thenReturn(graph);
Mockito.when(stx.storeInitialized()).thenReturn(true);
BackendStoreSystemInfo info = new BackendStoreSystemInfo(stx);
Assert.assertThrows(HugeException.class, () -> {
Whitebox.invoke(BackendStoreSystemInfo.class, "info", info);
}, e -> {
Assert.assertContains("There exists multiple backend info", e.getMessage());
});
}
use of com.baidu.hugegraph.backend.store.BackendStoreSystemInfo in project incubator-hugegraph by apache.
the class TestGraph method initBackend.
@Watched
protected void initBackend() {
BackendStoreSystemInfo sysInfo = this.graph.backendStoreSystemInfo();
if (!sysInfo.exists()) {
this.graph.initBackend();
} else {
// May reopen a closed graph
assert sysInfo.exists() && !this.graph.closed();
}
Id id = IdGenerator.of("server-tinkerpop");
this.graph.serverStarted(id, NodeRole.MASTER);
this.initedBackend = true;
}
use of com.baidu.hugegraph.backend.store.BackendStoreSystemInfo in project incubator-hugegraph by apache.
the class RaftBackendStoreProvider method initSystemInfo.
@Override
public void initSystemInfo(HugeGraph graph) {
this.checkOpened();
BackendStoreSystemInfo info = graph.backendStoreSystemInfo();
info.init();
this.notifyAndWaitEvent(Events.STORE_INITED);
LOG.debug("Graph '{}' system info has been initialized", this.graph());
/*
* Take the initiative to generate a snapshot, it can avoid this
* situation: when the server restart need to read the database
* (such as checkBackendVersionInfo), it happens that raft replays
* the truncate log, at the same time, the store has been cleared
* (truncate) but init-store has not been completed, which will
* cause reading errors.
* When restarting, load the snapshot first and then read backend,
* will not encounter such an intermediate state.
*/
this.createSnapshot();
LOG.debug("Graph '{}' snapshot has been created", this.graph());
}
use of com.baidu.hugegraph.backend.store.BackendStoreSystemInfo in project incubator-hugegraph by apache.
the class InitStore method initGraph.
private static void initGraph(String configPath) throws Exception {
LOG.info("Init graph with config file: {}", configPath);
HugeConfig config = new HugeConfig(configPath);
// Forced set RAFT_MODE to false when initializing backend
config.setProperty(CoreOptions.RAFT_MODE.name(), "false");
HugeGraph graph = (HugeGraph) GraphFactory.open(config);
BackendStoreSystemInfo sysInfo = graph.backendStoreSystemInfo();
try {
if (sysInfo.exists()) {
LOG.info("Skip init-store due to the backend store of '{}' " + "had been initialized", graph.name());
sysInfo.checkVersion();
} else {
initBackend(graph);
}
} finally {
graph.close();
}
}
Aggregations