@Override public boolean isEmpty() { return data.isEmpty(); }
@Override public boolean isEmpty() { return data.isEmpty(); }
@Override public boolean isEmpty() { return data.isEmpty(); }
@Override public boolean isEmpty() { return data.isEmpty(); }
/** * Restore the initial in-memory transaction state from a snapshot. */ private void restoreSnapshot(TransactionSnapshot snapshot) { LOG.info("Restoring transaction state from snapshot at " + snapshot.getTimestamp()); Preconditions.checkState(lastSnapshotTime == 0, "lastSnapshotTime has been set!"); Preconditions.checkState(readPointer == 0, "readPointer has been set!"); Preconditions.checkState(lastWritePointer == 0, "lastWritePointer has been set!"); Preconditions.checkState(invalid.isEmpty(), "invalid list should be empty!"); Preconditions.checkState(inProgress.isEmpty(), "inProgress map should be empty!"); Preconditions.checkState(committingChangeSets.isEmpty(), "committingChangeSets should be empty!"); Preconditions.checkState(committedChangeSets.isEmpty(), "committedChangeSets should be empty!"); LOG.info("Restoring snapshot of state: " + snapshot); lastSnapshotTime = snapshot.getTimestamp(); readPointer = snapshot.getReadPointer(); lastWritePointer = snapshot.getWritePointer(); invalid.addAll(snapshot.getInvalid()); inProgress.putAll(txnBackwardsCompatCheck(defaultLongTimeout, longTimeoutTolerance, snapshot.getInProgress())); committingChangeSets.putAll(snapshot.getCommittingChangeSets()); committedChangeSets.putAll(snapshot.getCommittedChangeSets()); }
/** * Restore the initial in-memory transaction state from a snapshot. */ private void restoreSnapshot(TransactionSnapshot snapshot) { LOG.info("Restoring transaction state from snapshot at " + snapshot.getTimestamp()); Preconditions.checkState(lastSnapshotTime == 0, "lastSnapshotTime has been set!"); Preconditions.checkState(readPointer == 0, "readPointer has been set!"); Preconditions.checkState(lastWritePointer == 0, "lastWritePointer has been set!"); Preconditions.checkState(invalid.isEmpty(), "invalid list should be empty!"); Preconditions.checkState(inProgress.isEmpty(), "inProgress map should be empty!"); Preconditions.checkState(committingChangeSets.isEmpty(), "committingChangeSets should be empty!"); Preconditions.checkState(committedChangeSets.isEmpty(), "committedChangeSets should be empty!"); LOG.info("Restoring snapshot of state: " + snapshot); lastSnapshotTime = snapshot.getTimestamp(); readPointer = snapshot.getReadPointer(); lastWritePointer = snapshot.getWritePointer(); invalid.addAll(snapshot.getInvalid()); inProgress.putAll(txnBackwardsCompatCheck(defaultLongTimeout, longTimeoutTolerance, snapshot.getInProgress())); committingChangeSets.putAll(snapshot.getCommittingChangeSets()); committedChangeSets.putAll(snapshot.getCommittedChangeSets()); }
if (!childWritePointers.isEmpty()) { invalidTxList.addAll(childWritePointers); inProgress.keySet().removeAll(childWritePointers);
if (!checkpointPointers.isEmpty()) {
@Override protected void encodeInProgress(BinaryEncoder encoder, Map<Long, TransactionManager.InProgressTx> inProgress) throws IOException { if (!inProgress.isEmpty()) { encoder.writeInt(inProgress.size()); for (Map.Entry<Long, TransactionManager.InProgressTx> entry : inProgress.entrySet()) { encoder.writeLong(entry.getKey()); // tx id encoder.writeLong(entry.getValue().getExpiration()); encoder.writeLong(entry.getValue().getVisibilityUpperBound()); encoder.writeInt(entry.getValue().getType().ordinal()); // write checkpoint tx IDs LongArrayList checkpointPointers = entry.getValue().getCheckpointWritePointers(); if (checkpointPointers != null && !checkpointPointers.isEmpty()) { encoder.writeInt(checkpointPointers.size()); for (int i = 0; i < checkpointPointers.size(); i++) { encoder.writeLong(checkpointPointers.getLong(i)); } } encoder.writeInt(0); } } encoder.writeInt(0); // zero denotes end of list as per AVRO spec }
@Override protected void encodeInProgress(BinaryEncoder encoder, Map<Long, TransactionManager.InProgressTx> inProgress) throws IOException { if (!inProgress.isEmpty()) { encoder.writeInt(inProgress.size()); for (Map.Entry<Long, TransactionManager.InProgressTx> entry : inProgress.entrySet()) { encoder.writeLong(entry.getKey()); // tx id encoder.writeLong(entry.getValue().getExpiration()); encoder.writeLong(entry.getValue().getVisibilityUpperBound()); encoder.writeInt(entry.getValue().getType().ordinal()); // write checkpoint tx IDs LongArrayList checkpointPointers = entry.getValue().getCheckpointWritePointers(); if (!checkpointPointers.isEmpty()) { encoder.writeInt(checkpointPointers.size()); for (int i = 0; i < checkpointPointers.size(); i++) { encoder.writeLong(checkpointPointers.getLong(i)); } } encoder.writeInt(0); } } encoder.writeInt(0); // zero denotes end of list as per AVRO spec }
@Override protected void encodeInProgress(BinaryEncoder encoder, Map<Long, TransactionManager.InProgressTx> inProgress) throws IOException { if (!inProgress.isEmpty()) { encoder.writeInt(inProgress.size()); for (Map.Entry<Long, TransactionManager.InProgressTx> entry : inProgress.entrySet()) { encoder.writeLong(entry.getKey()); // tx id encoder.writeLong(entry.getValue().getExpiration()); encoder.writeLong(entry.getValue().getVisibilityUpperBound()); encoder.writeInt(entry.getValue().getType().ordinal()); // write checkpoint tx IDs LongArrayList checkpointPointers = entry.getValue().getCheckpointWritePointers(); if (checkpointPointers != null && !checkpointPointers.isEmpty()) { encoder.writeInt(checkpointPointers.size()); for (int i = 0; i < checkpointPointers.size(); i++) { encoder.writeLong(checkpointPointers.getLong(i)); } } encoder.writeInt(0); } } encoder.writeInt(0); // zero denotes end of list as per AVRO spec }
@Override public void evaluate(Transaction transaction, LongArrayList recommendations, LongOpenHashSet userTransactions) { //if there is no ground truth, there is nothing to evaluate if (userTransactions == null || userTransactions.isEmpty()) { return; } // if the algorithm does not return any recommendations, count it as 0 if (recommendations.isEmpty()) { results.add(0); return; } // calculate the MRR // if the algorithm retrieves less than k recommendations, we calculate // the real k value for this case int realK = Math.min(k, recommendations.size()); // iterate over relevant items and calculate recall rank for (Long itemID : userTransactions) { for (int i = 0; i < realK; i++) { if (itemID == recommendations.getLong(i)) { results.add(1d/(i+1)); return; } } } //nothing found -> count as zero results.add(0); }
if (recommendations.isEmpty()) { results.add(0); return;