Esempio n. 1
0
  public ShardIterator(
      long tableId,
      boolean merged,
      Optional<Map<Integer, String>> bucketToNode,
      TupleDomain<RaptorColumnHandle> effectivePredicate,
      IDBI dbi) {
    this.merged = merged;
    this.bucketToNode = bucketToNode.orElse(null);
    ShardPredicate predicate = ShardPredicate.create(effectivePredicate, bucketToNode.isPresent());

    String sql;
    if (bucketToNode.isPresent()) {
      sql = "SELECT shard_uuid, bucket_number FROM %s WHERE %s ORDER BY bucket_number";
    } else {
      sql = "SELECT shard_uuid, node_ids FROM %s WHERE %s";
    }
    sql = format(sql, shardIndexTable(tableId), predicate.getPredicate());

    dao = onDemandDao(dbi, ShardDao.class);
    fetchNodes();

    try {
      connection = dbi.open().getConnection();
      statement = connection.prepareStatement(sql);
      enableStreamingResults(statement);
      predicate.bind(statement);
      log.debug("Running query: %s", statement);
      resultSet = statement.executeQuery();
    } catch (SQLException e) {
      close();
      throw metadataError(e);
    }
  }
 @BeforeMethod
 public void setup() throws Exception {
   IDBI dbi = new DBI("jdbc:h2:mem:test" + System.nanoTime());
   dummyHandle = dbi.open();
   dataDir = Files.createTempDir();
   shardManager = new DatabaseShardManager(dbi);
 }
Esempio n. 3
0
 @BeforeMethod
 public void setup() throws Exception {
   dbi = new DBI("jdbc:h2:mem:test" + System.nanoTime());
   dummyHandle = dbi.open();
   dao = dbi.onDemand(ShardManagerDao.class);
   createTablesWithRetry(dbi);
 }
 /**
  * @param entitySqlDaoTransactionWrapper transaction to execute
  * @param <ReturnType> object type to return from the transaction
  * @return result from the transaction fo type ReturnType
  */
 public <ReturnType> ReturnType execute(
     final EntitySqlDaoTransactionWrapper<ReturnType> entitySqlDaoTransactionWrapper) {
   final Handle handle = dbi.open();
   try {
     final EntitySqlDao<EntityModelDao<Entity>, Entity> entitySqlDao =
         handle.attach(InitialEntitySqlDao.class);
     return entitySqlDao.inTransaction(
         TransactionIsolationLevel.READ_COMMITTED,
         new JdbiTransaction<ReturnType, EntityModelDao<Entity>, Entity>(
             handle, entitySqlDaoTransactionWrapper));
   } finally {
     handle.close();
   }
 }
Esempio n. 5
0
  @BeforeMethod
  public void setup() throws Exception {
    temporary = createTempDir();
    File directory = new File(temporary, "data");
    storageService = new FileStorageService(directory);
    storageService.start();

    File backupDirectory = new File(temporary, "backup");
    fileBackupStore = new FileBackupStore(backupDirectory);
    fileBackupStore.start();
    backupStore = Optional.of(fileBackupStore);

    IDBI dbi = new DBI("jdbc:h2:mem:test" + System.nanoTime());
    dummyHandle = dbi.open();
    ShardManager shardManager = createShardManager(dbi);
    Duration discoveryInterval = new Duration(5, TimeUnit.MINUTES);
    recoveryManager =
        new ShardRecoveryManager(
            storageService, backupStore, nodeManager, shardManager, discoveryInterval, 10);

    shardRecorder = new InMemoryShardRecorder();
  }
Esempio n. 6
0
 private boolean _lock(long duration, TimeUnit unit) {
   if (handle == null) {
     handle = dbi.open();
     int got_lock =
         handle
             .createQuery("select get_lock(:name, :time)")
             .bind("name", name)
             .bind("time", unit.toSeconds(duration))
             .map(IntegerMapper.FIRST)
             .first();
     if (got_lock == 1) {
       return true;
     } else {
       handle.close();
       handle = null;
       return false;
     }
   } else {
     // we already have the lock!
     return true;
   }
 }