Exemplo n.º 1
0
  public void set(Key key, Value value, boolean isSetWithCompareVersion) {
    String databaseName = getDatabaseName(key);
    InnoDBDataBase db = getInnoDBDataBase(databaseName);
    int correspondingQueueID = key.getVNode() % config.getWriteThread();
    BlockingQueue<WriteOperation> writeOpQueue =
        operationQueues.get(String.valueOf(correspondingQueueID));
    Semaphore semaphore = new Semaphore(0);
    WriteOperation operation =
        new WriteOperation(db, WriteType.INSERT, key, value, isSetWithCompareVersion, semaphore);

    try {
      writeOpQueue.put(operation);
      Object result = operation.getResult();
      if (result instanceof RuntimeException) throw (RuntimeException) result;
    } catch (InterruptedException e) {
      e.printStackTrace();
    }
  }
Exemplo n.º 2
0
  public boolean delete(Key key) {
    String databaseName = getDatabaseName(key);
    InnoDBDataBase db = getInnoDBDataBase(databaseName);
    int correspondingQueueID = key.getVNode() % config.getWriteThread();
    BlockingQueue<WriteOperation> writeOpQueue =
        operationQueues.get(String.valueOf(correspondingQueueID));
    Semaphore semaphore = new Semaphore(0);
    WriteOperation operation =
        new WriteOperation(db, WriteType.DELETE, key, null, false, semaphore);

    try {
      writeOpQueue.put(operation);
      Object result = operation.getResult();
      if (result instanceof RuntimeException) throw (RuntimeException) result;
      return (Boolean) result;
    } catch (InterruptedException e) {
      e.printStackTrace();
    }

    return false;
  }