Search in sources :

Example 1 with OModifiableDistributedConfiguration

use of com.orientechnologies.orient.server.distributed.OModifiableDistributedConfiguration in project orientdb by orientechnologies.

the class OLocalClusterWrapperStrategy method readConfiguration.

protected ODistributedConfiguration readConfiguration() {
    if (cls.isAbstract())
        throw new IllegalArgumentException("Cannot create a new instance of abstract class");
    final ODatabaseDocument db = ODatabaseRecordThreadLocal.INSTANCE.get();
    int[] clusterIds = cls.getClusterIds();
    final List<String> clusterNames = new ArrayList<String>(clusterIds.length);
    for (int c : clusterIds) clusterNames.add(db.getClusterNameById(c).toLowerCase(Locale.ENGLISH));
    ODistributedConfiguration cfg = manager.getDatabaseConfiguration(databaseName);
    List<String> bestClusters = cfg.getOwnedClustersByServer(clusterNames, nodeName);
    if (bestClusters.isEmpty()) {
        // REBALANCE THE CLUSTERS
        final OModifiableDistributedConfiguration modifiableCfg = cfg.modify();
        manager.reassignClustersOwnership(nodeName, databaseName, modifiableCfg, true);
        cfg = modifiableCfg;
        // RELOAD THE CLUSTER LIST TO GET THE NEW CLUSTER CREATED (IF ANY)
        db.activateOnCurrentThread();
        clusterNames.clear();
        clusterIds = cls.getClusterIds();
        for (int c : clusterIds) clusterNames.add(db.getClusterNameById(c).toLowerCase(Locale.ENGLISH));
        bestClusters = cfg.getOwnedClustersByServer(clusterNames, nodeName);
        if (bestClusters.isEmpty()) {
            // FILL THE MAP CLUSTER/SERVERS
            final StringBuilder buffer = new StringBuilder();
            for (String c : clusterNames) {
                if (buffer.length() > 0)
                    buffer.append(" ");
                buffer.append(" ");
                buffer.append(c);
                buffer.append(":");
                buffer.append(cfg.getServers(c, null));
            }
            ODistributedServerLog.warn(this, manager.getLocalNodeName(), null, ODistributedServerLog.DIRECTION.NONE, "Cannot find best cluster for class '%s'. Configured servers for clusters %s are %s (dCfgVersion=%d)", cls.getName(), clusterNames, buffer.toString(), cfg.getVersion());
            throw new ODatabaseException("Cannot find best cluster for class '" + cls.getName() + "' on server '" + nodeName + "' (clusterStrategy=" + getName() + " dCfgVersion=" + cfg.getVersion() + ")");
        }
    }
    db.activateOnCurrentThread();
    final int[] newBestClusters = new int[bestClusters.size()];
    int i = 0;
    for (String c : bestClusters) newBestClusters[i++] = db.getClusterIdByName(c);
    this.localScopedClass = new OLocalScopedClass((OClassImpl) cls, newBestClusters);
    final ODistributedStorage storage = (ODistributedStorage) manager.getStorage(databaseName);
    lastVersion = storage.getConfigurationUpdated();
    return cfg;
}
Also used : ArrayList(java.util.ArrayList) OClassImpl(com.orientechnologies.orient.core.metadata.schema.OClassImpl) ODatabaseException(com.orientechnologies.orient.core.exception.ODatabaseException) OModifiableDistributedConfiguration(com.orientechnologies.orient.server.distributed.OModifiableDistributedConfiguration) ODatabaseDocument(com.orientechnologies.orient.core.db.document.ODatabaseDocument) ODistributedConfiguration(com.orientechnologies.orient.server.distributed.ODistributedConfiguration)

Example 2 with OModifiableDistributedConfiguration

use of com.orientechnologies.orient.server.distributed.OModifiableDistributedConfiguration in project orientdb by orientechnologies.

the class BasicShardingNoReplicaScenarioTest method executeTest.

@Override
public void executeTest() throws Exception {
    OHazelcastPlugin manager1 = (OHazelcastPlugin) serverInstance.get(0).getServerInstance().getDistributedManager();
    final OModifiableDistributedConfiguration databaseConfiguration = manager1.getDatabaseConfiguration(this.getDatabaseName()).modify();
    ODocument cfg = databaseConfiguration.getDocument();
    OrientGraphFactory localFactory = new OrientGraphFactory("plocal:target/server0/databases/" + getDatabaseName());
    OrientGraphNoTx graphNoTx = null;
    try {
        graphNoTx = localFactory.getNoTx();
        final OrientVertexType clientType = graphNoTx.createVertexType("Client", 1);
        OModifiableDistributedConfiguration dCfg = new OModifiableDistributedConfiguration(cfg);
        for (int i = 0; i < serverInstance.size(); ++i) {
            final String serverName = serverInstance.get(i).getServerInstance().getDistributedManager().getLocalNodeName();
            clientType.addCluster("client_" + serverName);
            dCfg.setServerOwner("client_" + serverName, serverName);
        }
        manager1.updateCachedDatabaseConfiguration(this.getDatabaseName(), dCfg, true);
        final OrientVertexType.OrientVertexProperty prop = clientType.createProperty("name", OType.STRING);
        prop.createIndex(OClass.INDEX_TYPE.NOTUNIQUE);
        assertTrue(graphNoTx.getRawGraph().getMetadata().getIndexManager().existsIndex("Client.name"));
        Thread.sleep(500);
        graphNoTx.getRawGraph().close();
        // writes on the three clusters
        executeMultipleWritesOnShards(executeTestsOnServers, "plocal");
        // check consistency (no-replica)
        checkAvailabilityOnShardsNoReplica(serverInstance, executeTestsOnServers);
        // network fault on server3
        System.out.println("Shutdown on server3.\n");
        simulateServerFault(serverInstance.get(2), "shutdown");
        assertFalse(serverInstance.get(2).isActive());
        waitForDatabaseIsOffline(executeTestsOnServers.get(2).getServerInstance().getDistributedManager().getLocalNodeName(), getDatabaseName(), 10000);
        // check consistency (no-replica)
        executeTestsOnServers.remove(2);
        checkAvailabilityOnShardsNoReplica(executeTestsOnServers, executeTestsOnServers);
        // this query doesn't return any result
        try {
            System.out.print("Checking that records on server3 are not available in the cluster...");
            graphNoTx = localFactory.getNoTx();
            ODatabaseRecordThreadLocal.INSTANCE.set(graphNoTx.getRawGraph());
            final String uniqueId = "client_asia-s2-t10-v0";
            Iterable<Vertex> it = graphNoTx.command(new OCommandSQL("select from Client where name = '" + uniqueId + "'")).execute();
            List<OrientVertex> result = new LinkedList<OrientVertex>();
            for (Vertex v : it) {
                result.add((OrientVertex) v);
            }
            assertEquals(0, result.size());
            System.out.println("Done");
            graphNoTx.getRawGraph().close();
            ODatabaseRecordThreadLocal.INSTANCE.set(null);
        } catch (Exception e) {
            e.printStackTrace();
            fail();
        }
        // restarting server3
        serverInstance.get(2).startServer(getDistributedServerConfiguration(serverInstance.get(SERVERS - 1)));
        System.out.println("Server 3 restarted.");
        assertTrue(serverInstance.get(2).isActive());
        waitForDatabaseIsOnline(0, serverInstance.get(2).getServerInstance().getDistributedManager().getLocalNodeName(), getDatabaseName(), 10000);
        // checking server3 status by querying a record inserted on it
        try {
            System.out.print("Checking server3 status by querying a record inserted on it...");
            localFactory = new OrientGraphFactory("plocal:target/server2/databases/" + getDatabaseName());
            graphNoTx = localFactory.getNoTx();
            ODatabaseRecordThreadLocal.INSTANCE.set(graphNoTx.getRawGraph());
            final String uniqueId = "client_asia-s2-t10-v0";
            Iterable<Vertex> it = graphNoTx.command(new OCommandSQL("select from Client where name = '" + uniqueId + "'")).execute();
            List<OrientVertex> result = new LinkedList<OrientVertex>();
            for (Vertex v : it) {
                result.add((OrientVertex) v);
            }
            assertEquals(1, result.size());
            graphNoTx.getRawGraph().close();
            ODatabaseRecordThreadLocal.INSTANCE.set(null);
        } catch (Exception e) {
            e.printStackTrace();
            fail(e.toString());
        }
        // check consistency (no-replica)
        executeTestsOnServers.add(serverInstance.get(2));
        checkAvailabilityOnShardsNoReplica(serverInstance, executeTestsOnServers);
    } catch (Exception e) {
        e.printStackTrace();
        fail(e.toString());
    } finally {
        if (!graphNoTx.getRawGraph().isClosed()) {
            ODatabaseRecordThreadLocal.INSTANCE.set(graphNoTx.getRawGraph());
            graphNoTx.getRawGraph().close();
            ODatabaseRecordThreadLocal.INSTANCE.set(null);
        }
    }
}
Also used : Vertex(com.tinkerpop.blueprints.Vertex) OrientVertex(com.tinkerpop.blueprints.impls.orient.OrientVertex) OHazelcastPlugin(com.orientechnologies.orient.server.hazelcast.OHazelcastPlugin) OrientVertex(com.tinkerpop.blueprints.impls.orient.OrientVertex) OModifiableDistributedConfiguration(com.orientechnologies.orient.server.distributed.OModifiableDistributedConfiguration) LinkedList(java.util.LinkedList) OCommandSQL(com.orientechnologies.orient.core.sql.OCommandSQL) OrientGraphFactory(com.tinkerpop.blueprints.impls.orient.OrientGraphFactory) OrientGraphNoTx(com.tinkerpop.blueprints.impls.orient.OrientGraphNoTx) OrientVertexType(com.tinkerpop.blueprints.impls.orient.OrientVertexType) ODocument(com.orientechnologies.orient.core.record.impl.ODocument)

Example 3 with OModifiableDistributedConfiguration

use of com.orientechnologies.orient.server.distributed.OModifiableDistributedConfiguration in project orientdb by orientechnologies.

the class IsolatedNodeRejoinScenarioTest method executeTest.

@Override
public void executeTest() throws Exception {
    /*
     * Test with quorum = 1
     */
    banner("Test with quorum = 2");
    System.out.print("\nChanging configuration (writeQuorum=2, autoDeploy=false)...");
    ODocument cfg = null;
    ServerRun server = serverInstance.get(2);
    OHazelcastPlugin manager = (OHazelcastPlugin) server.getServerInstance().getDistributedManager();
    OModifiableDistributedConfiguration databaseConfiguration = manager.getDatabaseConfiguration(getDatabaseName()).modify();
    cfg = databaseConfiguration.getDocument();
    cfg.field("writeQuorum", 2);
    cfg.field("autoDeploy", true);
    cfg.field("version", (Integer) cfg.field("version") + 1);
    manager.updateCachedDatabaseConfiguration(getDatabaseName(), databaseConfiguration, true);
    System.out.println("\nConfiguration updated.");
    // isolating server3
    System.out.println("Network fault on server3.\n");
    simulateServerFault(serverInstance.get(2), "net-fault");
    assertFalse(serverInstance.get(2).isActive());
    // execute writes on server1 and server2
    executeMultipleWrites(super.executeTestsOnServers, "plocal");
    // server3 joins the cluster
    System.out.println("Restart server3.\n");
    try {
        serverInstance.get(2).startServer(getDistributedServerConfiguration(server));
    } catch (Exception e) {
        fail();
    }
    // waiting for propagation
    waitForMultipleInsertsInClassPropagation(1000L, "Person", 5000L);
    // check consistency
    super.checkWritesAboveCluster(serverInstance, executeTestsOnServers);
}
Also used : ServerRun(com.orientechnologies.orient.server.distributed.ServerRun) OHazelcastPlugin(com.orientechnologies.orient.server.hazelcast.OHazelcastPlugin) OModifiableDistributedConfiguration(com.orientechnologies.orient.server.distributed.OModifiableDistributedConfiguration) ODocument(com.orientechnologies.orient.core.record.impl.ODocument)

Example 4 with OModifiableDistributedConfiguration

use of com.orientechnologies.orient.server.distributed.OModifiableDistributedConfiguration in project orientdb by orientechnologies.

the class Quorum1ScenarioTest method executeTest.

@Override
public void executeTest() throws Exception {
    /*
     * Test with quorum = 1
     */
    banner("Test with quorum = 1");
    System.out.print("\nChanging configuration (writeQuorum=1, autoDeploy=false)...");
    ODocument cfg = null;
    ServerRun server = serverInstance.get(0);
    OHazelcastPlugin manager = (OHazelcastPlugin) server.getServerInstance().getDistributedManager();
    OModifiableDistributedConfiguration databaseConfiguration = manager.getDatabaseConfiguration(getDatabaseName()).modify();
    cfg = databaseConfiguration.getDocument();
    cfg.field("writeQuorum", 1);
    cfg.field("autoDeploy", true);
    cfg.field("version", (Integer) cfg.field("version") + 1);
    manager.updateCachedDatabaseConfiguration(getDatabaseName(), databaseConfiguration, true);
    System.out.println("\nConfiguration updated.");
    // execute writes on server1 and server2
    executeMultipleWrites(super.executeTestsOnServers, "plocal");
    // waiting for propagation
    waitForMultipleInsertsInClassPropagation(executeTestsOnServers.size() * writerCount * count, "Person", 5000L);
    // check consistency
    super.checkWritesAboveCluster(serverInstance, executeTestsOnServers);
}
Also used : ServerRun(com.orientechnologies.orient.server.distributed.ServerRun) OHazelcastPlugin(com.orientechnologies.orient.server.hazelcast.OHazelcastPlugin) OModifiableDistributedConfiguration(com.orientechnologies.orient.server.distributed.OModifiableDistributedConfiguration) ODocument(com.orientechnologies.orient.core.record.impl.ODocument)

Example 5 with OModifiableDistributedConfiguration

use of com.orientechnologies.orient.server.distributed.OModifiableDistributedConfiguration in project orientdb by orientechnologies.

the class TwoClientsRecordUpdateTxOnTwoServersWithQuorum2ScenarioTest method setWriteQuorum.

private void setWriteQuorum(int quorum) throws InterruptedException {
    OHazelcastPlugin manager = (OHazelcastPlugin) serverInstance.get(0).getServerInstance().getDistributedManager();
    OModifiableDistributedConfiguration databaseConfiguration = manager.getDatabaseConfiguration(getDatabaseName()).modify();
    ODocument cfg = databaseConfiguration.getDocument();
    cfg.field("writeQuorum", quorum);
    manager.updateCachedDatabaseConfiguration(getDatabaseName(), databaseConfiguration, true);
    Thread.sleep(100);
}
Also used : OHazelcastPlugin(com.orientechnologies.orient.server.hazelcast.OHazelcastPlugin) OModifiableDistributedConfiguration(com.orientechnologies.orient.server.distributed.OModifiableDistributedConfiguration) ODocument(com.orientechnologies.orient.core.record.impl.ODocument)

Aggregations

OModifiableDistributedConfiguration (com.orientechnologies.orient.server.distributed.OModifiableDistributedConfiguration)6 ODocument (com.orientechnologies.orient.core.record.impl.ODocument)5 OHazelcastPlugin (com.orientechnologies.orient.server.hazelcast.OHazelcastPlugin)5 ServerRun (com.orientechnologies.orient.server.distributed.ServerRun)3 LinkedList (java.util.LinkedList)2 ODatabaseDocument (com.orientechnologies.orient.core.db.document.ODatabaseDocument)1 ODatabaseDocumentTx (com.orientechnologies.orient.core.db.document.ODatabaseDocumentTx)1 ODatabaseException (com.orientechnologies.orient.core.exception.ODatabaseException)1 OClassImpl (com.orientechnologies.orient.core.metadata.schema.OClassImpl)1 OCommandSQL (com.orientechnologies.orient.core.sql.OCommandSQL)1 ODistributedConfiguration (com.orientechnologies.orient.server.distributed.ODistributedConfiguration)1 Vertex (com.tinkerpop.blueprints.Vertex)1 OrientGraphFactory (com.tinkerpop.blueprints.impls.orient.OrientGraphFactory)1 OrientGraphNoTx (com.tinkerpop.blueprints.impls.orient.OrientGraphNoTx)1 OrientVertex (com.tinkerpop.blueprints.impls.orient.OrientVertex)1 OrientVertexType (com.tinkerpop.blueprints.impls.orient.OrientVertexType)1 IOException (java.io.IOException)1 ArrayList (java.util.ArrayList)1 Callable (java.util.concurrent.Callable)1 ExecutorService (java.util.concurrent.ExecutorService)1