Package com.splout.db.dnode

Examples of com.splout.db.dnode.DNode


      config = SploutConfiguration.getTestConfig();
      // we need to change some props for avoiding conflicts, ports, etc
      config.setProperty(DNodeProperties.PORT, config.getInt(DNodeProperties.PORT) + i);
      config.setProperty(DNodeProperties.DATA_FOLDER, config.getString(DNodeProperties.DATA_FOLDER) + "-" + i);
      config.setProperty(FetcherProperties.TEMP_DIR, config.getString(FetcherProperties.TEMP_DIR) + "-" + i);
      DNode dnode = new DNode(config, new DNodeHandler());
      dnode.init();
    }
  }
View Full Code Here


*/
public class OneShardEnsemble {

  public void runForever() throws Exception {
    SploutConfiguration config = SploutConfiguration.getTestConfig();
    DNode dnode = new DNode(config, new DNodeHandler());
    dnode.init();
    QNode qnode = new QNode();
    qnode.start(config, new QNodeHandler());
  }
View Full Code Here

      List<PartitionEntry> partitions = new ArrayList<PartitionEntry>();
      List<ReplicationEntry> replicationEntries = new ArrayList<ReplicationEntry>();
      for(int i = 0; i < 5; i++) {
        SploutConfiguration dNodeConfig = SploutConfiguration.getTestConfig();
        // We instantiate a DNode with a handler that returns "DNode" + i for any query
        DNode dnode = TestUtils.getTestDNode(dNodeConfig, new TellIDHandler("DNode" + i), "dnode-"
            + this.getClass().getName() + "-" + i);
        dNodes.add(dnode);
        // Define the partition for this DNode
        // DNode 0 will have [10, 20), DNode 1 [20, 30], ...
        PartitionEntry partitionEntry = new PartitionEntry();
        partitionEntry.setMin((i * 10 + 10) + "");
        partitionEntry.setMax((i * 10 + 20) + "");
        partitionEntry.setShard(i);
        partitions.add(partitionEntry);
        // And the replication
        ReplicationEntry repEntry = new ReplicationEntry();
        repEntry.setShard(i);
        repEntry.setNodes(Arrays.asList(new String[] { "localhost:" + dNodeConfig.getInt(DNodeProperties.PORT) }));
        replicationEntries.add(repEntry);
      }

      Tablespace tablespace1 = new Tablespace(new PartitionMap(partitions), new ReplicationMap(replicationEntries), 1l,
          0l);
      handler.getContext().getTablespaceVersionsMap().put(new TablespaceVersion("tablespace1", 1l), tablespace1);
      handler.getContext().getCurrentVersionsMap().put("tablespace1", 1l);

      // The following has to be read as: multi-query range [23-25)
      // The impacted shard will be 1 [20-30)
      List<String> keyMins = Arrays.asList(new String[] { "23" });
      List<String> keyMaxs = Arrays.asList(new String[] { "25" });

      ArrayList<QueryStatus> resultObj = handler.multiQuery("tablespace1", keyMins, keyMaxs, "SELECT 1;");
      assertEquals(1, resultObj.size());

      assertTrue(1 == resultObj.get(0).getShard());
      assertEquals("DNode1", resultObj.get(0).getResult().get(0));

      // The following has to be read as: multi-query [13-25) Union [45-55).
      // The impacted shards will be 0 [10-20), 1 [20, 30), 3 [40, 50), 5 [50, 60)
      keyMins = Arrays.asList(new String[] { "13", "45" });
      keyMaxs = Arrays.asList(new String[] { "25", "55" });

      resultObj = handler.multiQuery("tablespace1", keyMins, keyMaxs, "SELECT 1;");

      assertEquals(4, resultObj.size());

      // The impacted shards will be 0 [0-10), 1 [10, 20), 3 [30, 40), 4 [40, 50)
      assertTrue(0 == resultObj.get(0).getShard());
      assertTrue(1 == resultObj.get(1).getShard());
      assertTrue(3 == resultObj.get(2).getShard());
      assertTrue(4 == resultObj.get(3).getShard());

      assertEquals("DNode0", resultObj.get(0).getResult().get(0));
      assertEquals("DNode1", resultObj.get(1).getResult().get(0));
      assertEquals("DNode3", resultObj.get(2).getResult().get(0));
      assertEquals("DNode4", resultObj.get(3).getResult().get(0));

      // The following has to be read as: multi-query the opened range (-Infinity, Infinity) regardless of the key type.
      // The impacted shards will be all: 0, 1, 2, 3, 4
      keyMins = Arrays.asList(new String[] {});
      keyMaxs = Arrays.asList(new String[] {});

      resultObj = handler.multiQuery("tablespace1", keyMins, keyMaxs, "SELECT 1;");

      assertEquals(5, resultObj.size());

      for(int i = 0; i < 5; i++) {
        assertTrue(i == resultObj.get(i).getShard());
        assertEquals("DNode" + i, resultObj.get(i).getResult().get(0));
      }
    } finally {
      handler.close();
      for(DNode dnode : dNodes) {
        dnode.stop();
      }
      Hazelcast.shutdownAll();
    }
  }
View Full Code Here

    config.setProperty(QNodeProperties.REPLICA_BALANCE_ENABLE, true);
    config.setProperty(QNodeProperties.WARMING_TIME, 0);
    config.setProperty(QNodeProperties.DEPLOY_SECONDS_TO_CHECK_ERROR, 1); // this has to be quick for testing
   
    DNodeHandler dHandler = new DNodeHandler();
    DNode dnode1 = TestUtils
        .getTestDNode(config1, dHandler, "dnode-" + this.getClass().getName() + "-1");

    SucceedingDNodeHandler succeed = new SucceedingDNodeHandler();
    DNode dnode2 = TestUtils.getTestDNode(config2, succeed, "dnode-" + this.getClass().getName() + "-2");

    try {
      handler.init(config);

      ReplicationEntry repEntry1 = new ReplicationEntry(0, dnode1.getAddress(), dnode2.getAddress());

      DeployRequest deployRequest1 = new DeployRequest();
      deployRequest1.setTablespace("t1");
      deployRequest1.setPartitionMap(PartitionMap.oneShardOpenedMap().getPartitionEntries());
      deployRequest1.setReplicationMap(Arrays.asList(repEntry1));

      File fakeDeployFolder = new File(DEPLOY_FOLDER_THAT_DOESNT_EXIST);
      // Remember we don't create the folder on purpose for making the DNode fail
      deployRequest1.setData_uri(fakeDeployFolder.toURI().toString());

      List<DeployRequest> l = new ArrayList<DeployRequest>();
      l.add(deployRequest1);

      handler.deploy(l);

      // wait until deploy finished
      new TestUtils.NotWaitingForeverCondition() {
       
        @Override
        public boolean endCondition() {
          return handler.getContext().getTablespaceVersionsMap().size() == 1;
        }
      }.waitAtMost(5000);

      // wait until replica balancer re-balanced the under-replicated partition
      new TestUtils.NotWaitingForeverCondition() {
       
        @Override
        public boolean endCondition() {
          ReplicationMap map = handler.getContext().getTablespaceVersionsMap().values().iterator().next().getReplicationMap();
          return map.getReplicationEntries().get(0).getNodes().size() == 2;
        }
      }.waitAtMost(5000);

      // everything OK
    } finally {
      handler.close();
      dnode1.stop();
      dnode2.stop();
      Hazelcast.shutdownAll();
    }
  }
View Full Code Here

    fetcherTmp.mkdir();
    CatchAndRetry dNodeInit = new CatchAndRetry(TTransportException.class, 50) {

      @Override
      public void businessLogic() throws Throwable {
        DNode dNode = new DNode(testConfig, handler);
        dNode.init();
        reference.set(dNode);
      }
     
      @Override
      public void retryLogic() {
View Full Code Here

      public String testCommand(String command) throws DNodeException {
        // TODO Auto-generated method stub
        return null;
      }
    };
    DNode dnode1 = TestUtils.getTestDNode(testConfig, okQueryHandler, "dnode-" + this.getClass().getName() + "-1");
    DNode dnode2 = TestUtils.getTestDNode(testConfig, okQueryHandler, "dnode-" + this.getClass().getName() + "-2");
   
    List<ReplicationEntry> rEntries = new ArrayList<ReplicationEntry>();
    rEntries.add(new ReplicationEntry(0, dnode1.getAddress(), dnode2.getAddress()));

    QNodeHandlerContext context = new QNodeHandlerContext(testConfig, null);
   
    Tablespace tablespace = new Tablespace(PartitionMap.oneShardOpenedMap(), new ReplicationMap(rEntries), 0, 0);
    context.getTablespaceVersionsMap().put(new TablespaceVersion("t1", 0l), tablespace);
View Full Code Here

      public String testCommand(String command) throws DNodeException {
        // TODO Auto-generated method stub
        return null;
      }
    };
    DNode dnode1 = TestUtils.getTestDNode(testConfig, okQueryHandler, "dnode-" + this.getClass().getName() + "-1");
    DNode dnode2 = TestUtils.getTestDNode(testConfig, okQueryHandler, "dnode-" + this.getClass().getName() + "-2");
   
    List<ReplicationEntry> rEntries = new ArrayList<ReplicationEntry>();
    rEntries.add(new ReplicationEntry(0, dnode1.getAddress(), "fakeaddress:1111", dnode2.getAddress(), "fakeaddress:2222"));

    QNodeHandlerContext context = new QNodeHandlerContext(testConfig, null);
   
    Tablespace tablespace = new Tablespace(PartitionMap.oneShardOpenedMap(), new ReplicationMap(rEntries), 0, 0);
    context.getTablespaceVersionsMap().put(new TablespaceVersion("t1", 0l), tablespace);
View Full Code Here

      public String testCommand(String command) throws DNodeException {
        // TODO Auto-generated method stub
        return null;
      }
    };
    DNode dnode1 = TestUtils.getTestDNode(testConfig, okQueryHandler, "dnode-" + this.getClass().getName() + "-1");
    DNode dnode2 = TestUtils.getTestDNode(testConfig, okQueryHandler, "dnode-" + this.getClass().getName() + "-2");
   
    List<ReplicationEntry> rEntries = new ArrayList<ReplicationEntry>();
    rEntries.add(new ReplicationEntry(0, dnode1.getAddress(), "failingaddress:1111", dnode2.getAddress(), "failingaddress:2222"));

    QNodeHandlerContext context = new QNodeHandlerContext(testConfig, null);
   
    Tablespace tablespace = new Tablespace(PartitionMap.oneShardOpenedMap(), new ReplicationMap(rEntries), 0, 0);
    context.getTablespaceVersionsMap().put(new TablespaceVersion("t1", 0l), tablespace);
View Full Code Here

   
    SploutConfiguration config1 = SploutConfiguration.getTestConfig();
    SploutConfiguration config2 = SploutConfiguration.getTestConfig();
    config2.setProperty(DNodeProperties.DATA_FOLDER, config1.getString(DNodeProperties.DATA_FOLDER) + "-" + 1);
   
    DNode dnode1 = TestUtils.getTestDNode(config1, failingDHandler, "dnode-" + this.getClass().getName() + "-1");
    DNode dnode2 = TestUtils.getTestDNode(config2, dHandler, "dnode-" + this.getClass().getName() + "-2");

    try {
      ReplicationEntry repEntry = new ReplicationEntry(0, dnode1.getAddress(), dnode2.getAddress());
      Tablespace tablespace1 = new Tablespace(PartitionMap.oneShardOpenedMap(), new ReplicationMap(Arrays.asList(repEntry)), 1l, 0l);
      handler.getContext().getTablespaceVersionsMap().put(new TablespaceVersion("tablespace1", 1l), tablespace1);
      handler.getContext().getCurrentVersionsMap().put("tablespace1", 1l);

      QueryStatus qStatus = handler.query("tablespace1", "2", "SELECT 1;", null);
      Assert.assertEquals(new Integer(0), qStatus.getShard());
      Assert.assertEquals("[1]", qStatus.getResult().toString());
    } finally {
      handler.close();
      dnode1.stop();
      dnode2.stop();
      Hazelcast.shutdownAll();
    }
  }
View Full Code Here

          return true;
        }
      }
    }.waitAtMost(5000);

    final DNode dnode1 = getdNodes().get(1);

    final Set<Integer> partitionsByNode1 = new HashSet<Integer>();
    partitionsByNode1.add(0);
    partitionsByNode1.add(1);

    // shutdown DNode1 and see what happens with auto-rebalancing
    // the "partitionsByNode1" will become under-replicated and after a short period of time should be balanced
    dnode1.testCommand(TestCommands.SHUTDOWN.toString());

    // waiting until the system becomes under-replicated
    new TestUtils.NotWaitingForeverCondition() {

      @Override
      public boolean endCondition() {
        try {
          boolean dnode1NotPresent = true;
          for(int i = 0; i < N_QNODES; i++) {
            Map.Entry<String, Tablespace> tEntry = clients[i].overview().getTablespaceMap().entrySet()
                .iterator().next();
            ReplicationMap currentReplicationMap = tEntry.getValue().getReplicationMap();
            for(ReplicationEntry entry : currentReplicationMap.getReplicationEntries()) {
              if(entry.getNodes().contains(dnode1.getAddress())) {
                dnode1NotPresent = false;
              }
            }
          }
          return dnode1NotPresent;
        } catch(IOException e) {
          // test failed
          e.printStackTrace();
          return true;
        }
      }
    }.waitAtMost(5000);

    // waiting now until the system recovers itself without dnode1
    new TestUtils.NotWaitingForeverCondition() {

      @Override
      public boolean endCondition() {
        try {
          boolean balanced = true;
          for(int i = 0; i < N_QNODES; i++) {
            Map.Entry<String, Tablespace> tEntry = clients[i].overview().getTablespaceMap().entrySet()
                .iterator().next();
            ReplicationMap currentReplicationMap = tEntry.getValue().getReplicationMap();
            for(ReplicationEntry entry : currentReplicationMap.getReplicationEntries()) {
              if(entry.getNodes().size() < entry.getExpectedReplicationFactor()) {
                balanced = false;
              }
            }
          }
          return balanced;
        } catch(IOException e) {
          // test failed
          e.printStackTrace();
          return true;
        }
      }
    }.waitAtMost(5000);

    // now we bring back dnode1 to life
    // what will happen now is that the partitions it seves will be over-replicated
    dnode1.testCommand(TestCommands.RESTART.toString());

    // waiting now until the system is over-replicated
    new TestUtils.NotWaitingForeverCondition() {

      @Override
View Full Code Here

TOP

Related Classes of com.splout.db.dnode.DNode

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.