コード例 #1
0
  public void writeLogEntry(LogEntry logEntry) throws Throwable {
    List<Mutation> slice = new ArrayList<Mutation>();
    slice.add(getMutation(LogEntryColumns.KS.toString(), logEntry.getKeyspace()));
    slice.add(getMutation(LogEntryColumns.CF.toString(), logEntry.getColumnFamily()));
    slice.add(getMutation(LogEntryColumns.ROW.toString(), logEntry.getRowKey()));
    slice.add(getMutation(LogEntryColumns.STATUS.toString(), logEntry.getStatus().toString()));
    slice.add(
        getMutation(LogEntryColumns.TIMESTAMP.toString(), Long.toString(logEntry.getTimestamp())));
    slice.add(getMutation(LogEntryColumns.HOST.toString(), logEntry.getHost()));
    if (logEntry.hasErrors()) {
      for (String errorKey : logEntry.getErrors().keySet()) {
        slice.add(getMutation(errorKey, logEntry.getErrors().get(errorKey)));
      }
    }

    if (ConfigurationStore.getStore().shouldWriteColumns()) {
      for (ColumnOperation operation : logEntry.getOperations()) {
        if (operation.isDelete()) {
          slice.add(getMutation(operation.getName(), OperationType.DELETE));
        } else {
          slice.add(getMutation(operation.getName(), OperationType.UPDATE));
        }
      }
    }
    Map<ByteBuffer, Map<String, List<Mutation>>> mutationMap =
        new HashMap<ByteBuffer, Map<String, List<Mutation>>>();
    Map<String, List<Mutation>> cfMutations = new HashMap<String, List<Mutation>>();
    cfMutations.put(COLUMN_FAMILY, slice);

    ByteBuffer rowKey = ByteBufferUtil.bytes(logEntry.getUuid());
    mutationMap.put(rowKey, cfMutations);
    getConnection(KEYSPACE).batch_mutate(mutationMap, logEntry.getConsistencyLevel());
  }
コード例 #2
0
 public void removeLogEntry(LogEntry logEntry) throws Throwable {
   long deleteTime = System.currentTimeMillis() * 1000;
   ColumnPath path = new ColumnPath(COLUMN_FAMILY);
   getConnection(KEYSPACE)
       .remove(ByteBufferUtil.bytes(logEntry.getUuid()), path, deleteTime, ConsistencyLevel.ALL);
 }