@Override public void delete(Long key) { logger.trace("delete.enter; key: {}", key); Long position = transactions.remove(key); if (position != null) { int pos = position.intValue(); bits.clear(pos2bit(pos)); buff.put(pos, (byte) TransactionState.commited.ordinal()); buff.putInt(0, bits.cardinality()); } logger.trace("delete.exit; deleted: {}; tx count: {}", position != null, bits.cardinality()); }
/** * {@inheritDoc} */ public Map<String, Object> convert() { Map<String, Object> result = new HashMap<>(); result.put("txId", txId); result.put("started at", new Date(startedAt).toString()); result.put("started by", startedBy); long finished; if (finishedAt > 0) { finished = finishedAt; } else { finished = System.currentTimeMillis(); } result.put("duration", DateUtils.getDuration(finished - startedAt)); result.put("isolation", txIsolation.toString()); result.put("state", txState.toString()); result.put("docs created", docsCreated); result.put("docs updated", docsUpdated); result.put("docs deleted", docsDeleted); return result; }
private Transaction readTx() { TransactionState state = TransactionState.values()[buff.get()]; long id = buff.getLong(); long start = buff.getLong(); long finish = buff.getLong(); TransactionIsolation isol = TransactionIsolation.values()[buff.get()]; byte[] by26 = new byte[byLen]; buff.get(by26); int sz = 0; while (sz < byLen && by26[sz] > 0) { sz++; } String owner = new String(by26, 0, sz); Transaction xtx = new Transaction(id, start, finish, owner, isol, state); xtx.updateCounters(buff.getInt(), buff.getInt(), buff.getInt()); return xtx; }
@Override public Transaction read(ObjectDataInput in) throws IOException { ContentDataPool cdPool = ContentDataPool.getDataPool(); Transaction xTrans = new Transaction(in.readLong(), in.readLong(), in.readLong(), cdPool.intern(in.readUTF()), TransactionIsolation.values()[in.readInt()], TransactionState.values()[in.readInt()]); xTrans.updateCounters(in.readInt(), in.readInt(), in.readInt()); return xTrans; }
@Override public void deleteAll(Collection<Long> keys) { logger.trace("deleteAll.enter; keys: {}", keys); int cnt = 0; for (Long key: keys) { Long position = transactions.remove(key); if (position != null) { int pos = position.intValue(); bits.clear(pos2bit(pos)); buff.put(pos, (byte) TransactionState.commited.ordinal()); buff.putInt(0, bits.cardinality()); cnt++; } } logger.trace("deleteAll.exit; deleted: {}; tx count: {}", cnt, bits.cardinality()); }
private void writeTx(Transaction xtx) { buff.put((byte) xtx.getTxState().ordinal()); buff.putLong(xtx.getTxId()); buff.putLong(xtx.getStartedAt()); buff.putLong(xtx.getFinishedAt()); buff.put((byte) xtx.getTxIsolation().ordinal()); buff.putInt(xtx.getDocsCreated()); buff.putInt(xtx.getDocsUpdated()); buff.putInt(xtx.getDocsDeleted()); byte[] by = xtx.getStartedBy().getBytes(); byte[] by26 = new byte[byLen]; for (int i=0; i < by.length; i++) { by26[i] = by[i]; } buff.put(by26); //buff.force(); }
@Override public void write(ObjectDataOutput out, Transaction xTrans) throws IOException { out.writeLong(xTrans.getTxId()); out.writeLong(xTrans.getStartedAt()); out.writeLong(xTrans.getFinishedAt()); out.writeUTF(xTrans.getStartedBy()); out.writeInt(xTrans.getTxIsolation().ordinal()); out.writeInt(xTrans.getTxState().ordinal()); out.writeInt(xTrans.getDocsCreated()); out.writeInt(xTrans.getDocsUpdated()); out.writeInt(xTrans.getDocsDeleted()); }