Search in sources :

Example 1 with BackendStoreSystemInfo

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");
        }
    }
}
Also used : HugeGraph(com.baidu.hugegraph.HugeGraph) BackendStoreSystemInfo(com.baidu.hugegraph.backend.store.BackendStoreSystemInfo) BackendException(com.baidu.hugegraph.backend.BackendException) NotSupportException(com.baidu.hugegraph.exception.NotSupportException) AuthenticationException(org.apache.tinkerpop.gremlin.server.auth.AuthenticationException) BackendException(com.baidu.hugegraph.backend.BackendException)

Example 2 with BackendStoreSystemInfo

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());
    });
}
Also used : HugeGraph(com.baidu.hugegraph.HugeGraph) BackendStoreSystemInfo(com.baidu.hugegraph.backend.store.BackendStoreSystemInfo) SchemaTransaction(com.baidu.hugegraph.backend.tx.SchemaTransaction) Test(org.junit.Test)

Example 3 with BackendStoreSystemInfo

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;
}
Also used : BackendStoreSystemInfo(com.baidu.hugegraph.backend.store.BackendStoreSystemInfo) Id(com.baidu.hugegraph.backend.id.Id) Watched(com.baidu.hugegraph.perf.PerfUtil.Watched)

Example 4 with BackendStoreSystemInfo

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());
}
Also used : BackendStoreSystemInfo(com.baidu.hugegraph.backend.store.BackendStoreSystemInfo)

Example 5 with BackendStoreSystemInfo

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();
    }
}
Also used : HugeGraph(com.baidu.hugegraph.HugeGraph) BackendStoreSystemInfo(com.baidu.hugegraph.backend.store.BackendStoreSystemInfo) HugeConfig(com.baidu.hugegraph.config.HugeConfig)

Aggregations

BackendStoreSystemInfo (com.baidu.hugegraph.backend.store.BackendStoreSystemInfo)5 HugeGraph (com.baidu.hugegraph.HugeGraph)3 BackendException (com.baidu.hugegraph.backend.BackendException)1 Id (com.baidu.hugegraph.backend.id.Id)1 SchemaTransaction (com.baidu.hugegraph.backend.tx.SchemaTransaction)1 HugeConfig (com.baidu.hugegraph.config.HugeConfig)1 NotSupportException (com.baidu.hugegraph.exception.NotSupportException)1 Watched (com.baidu.hugegraph.perf.PerfUtil.Watched)1 AuthenticationException (org.apache.tinkerpop.gremlin.server.auth.AuthenticationException)1 Test (org.junit.Test)1