use of org.corfudb.protocols.logprotocol.SMREntry in project CorfuDB by CorfuDB.
the class CorfuCompileProxy method logUpdateInner.
private long logUpdateInner(String smrUpdateFunction, final boolean keepUpcallResult, Object[] conflictObject, Object... args) {
// redirect us to a transactional context first.
if (TransactionalContext.isInTransaction()) {
try {
// We generate an entry to avoid exposing the serializer to the tx context.
SMREntry entry = new SMREntry(smrUpdateFunction, args, serializer);
return TransactionalContext.getCurrentContext().logUpdate(this, entry, conflictObject);
} catch (Exception e) {
log.debug("Update[{}] Exception: {}", this, e);
this.abortTransaction(e);
}
}
// If we aren't in a transaction, we can just write the modification.
// We need to add the acquired token into the pending upcall list.
SMREntry smrEntry = new SMREntry(smrUpdateFunction, args, serializer);
long address = underlyingObject.logUpdate(smrEntry, keepUpcallResult);
log.trace("Update[{}] {}@{} ({}) conflictObj={}", this, smrUpdateFunction, address, args, conflictObject);
return address;
}
use of org.corfudb.protocols.logprotocol.SMREntry in project CorfuDB by CorfuDB.
the class OptimisticTransactionalContext method tryCommitAllProxies.
/** Try to commit the optimistic updates to each proxy. */
protected void tryCommitAllProxies() {
// First, get the committed entry
// in order to get the backpointers
// and the underlying SMREntries.
ILogData committedEntry = this.builder.getRuntime().getAddressSpaceView().read(commitAddress);
updateAllProxies(x -> {
log.trace("Commit[{}] Committing {}", this, x);
x.getUnderlyingObject().optimisticCommitUnsafe();
x.getUnderlyingObject().syncObjectUnsafe(commitAddress - 1);
List<SMREntry> committedWrites = getWriteSetEntryList(x.getStreamID());
List<SMREntry> entryWrites = ((ISMRConsumable) committedEntry.getPayload(this.getBuilder().runtime)).getSMRUpdates(x.getStreamID());
if (committedWrites.size() == entryWrites.size()) {
IntStream.range(0, committedWrites.size()).forEach(i -> {
if (committedWrites.get(i).isUndoable()) {
entryWrites.get(i).setUndoRecord(committedWrites.get(i).getUndoRecord());
}
});
}
x.getUnderlyingObject().seek(commitAddress + 1);
log.trace("Commit[{}] Committed {}", this, x);
});
}
use of org.corfudb.protocols.logprotocol.SMREntry in project CorfuDB by CorfuDB.
the class CheckpointWriter method appendObjectState.
/** Append zero or more CONTINUATION records to this
* object's stream. Each will contain a fraction of
* the state of the object that we're checkpointing
* (up to batchSize items at a time).
*
* Corfu client transaction management, if desired, is the
* caller's responsibility.
*
* The Iterators class appears to preserve the laziness
* of Stream processing; we don't wish to use more
* memory than strictly necessary to generate the
* checkpoint. NOTE: It would be even more useful if
* the map had a lazy iterator: the eagerness of
* map.keySet().stream() is not ideal, but at least
* it should be much smaller than the entire map.
*
* NOTE: The postAppendFunc lambda is executed in the
* current thread context, i.e., inside of a Corfu
* transaction, and that transaction will be *aborted*
* at the end of this function. Any Corfu data
* modifying ops will be undone by the TXAbort().
*
* @return Stream of global log addresses of the
* CONTINUATION records written.
*/
public List<Long> appendObjectState() {
ImmutableMap<CheckpointEntry.CheckpointDictKey, String> mdKV = ImmutableMap.copyOf(this.mdKV);
List<Long> continuationAddresses = new ArrayList<>();
Iterators.partition(map.keySet().stream().map(k -> {
return new SMREntry("put", new Object[] { keyMutator.apply(k), valueMutator.apply(map.get(k)) }, serializer);
}).iterator(), batchSize).forEachRemaining(entries -> {
MultiSMREntry smrEntries = new MultiSMREntry();
for (int i = 0; i < ((List) entries).size(); i++) {
smrEntries.addTo((SMREntry) ((List) entries).get(i));
}
CheckpointEntry cp = new CheckpointEntry(CheckpointEntry.CheckpointEntryType.CONTINUATION, author, checkpointID, mdKV, smrEntries);
long pos = sv.append(Collections.singleton(streamID), cp, null);
postAppendFunc.accept(cp, pos);
continuationAddresses.add(pos);
numEntries++;
numBytes += cp.getSmrEntriesBytes();
});
return continuationAddresses;
}
Aggregations