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()); }
public boolean isOld(LogEntry logEntry) { long now = System.currentTimeMillis(); long age = now - logEntry.getTimestamp(); return (age > DistributedCommitLog.MAX_LOG_ENTRY_AGE); }