Search in sources :

Example 6 with SMREntry

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;
}
Also used : SMREntry(org.corfudb.protocols.logprotocol.SMREntry) TransactionAbortedException(org.corfudb.runtime.exceptions.TransactionAbortedException) NetworkException(org.corfudb.runtime.exceptions.NetworkException)

Example 7 with SMREntry

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);
    });
}
Also used : ILogData(org.corfudb.protocols.wireprotocol.ILogData) ISMRConsumable(org.corfudb.protocols.logprotocol.ISMRConsumable) SMREntry(org.corfudb.protocols.logprotocol.SMREntry)

Example 8 with SMREntry

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;
}
Also used : Setter(lombok.Setter) java.util(java.util) TransactionalContext(org.corfudb.runtime.object.transactions.TransactionalContext) Getter(lombok.Getter) ImmutableMap(com.google.common.collect.ImmutableMap) LocalDateTime(java.time.LocalDateTime) AbstractTransactionalContext(org.corfudb.runtime.object.transactions.AbstractTransactionalContext) SMRMap(org.corfudb.runtime.collections.SMRMap) StreamsView(org.corfudb.runtime.view.StreamsView) Function(java.util.function.Function) Iterators(com.google.common.collect.Iterators) CheckpointEntry(org.corfudb.protocols.logprotocol.CheckpointEntry) MultiSMREntry(org.corfudb.protocols.logprotocol.MultiSMREntry) Consumer(java.util.function.Consumer) SMREntry(org.corfudb.protocols.logprotocol.SMREntry) TokenResponse(org.corfudb.protocols.wireprotocol.TokenResponse) BiConsumer(java.util.function.BiConsumer) TransactionType(org.corfudb.runtime.object.transactions.TransactionType) ISerializer(org.corfudb.util.serializer.ISerializer) Serializers(org.corfudb.util.serializer.Serializers) CheckpointEntry(org.corfudb.protocols.logprotocol.CheckpointEntry) MultiSMREntry(org.corfudb.protocols.logprotocol.MultiSMREntry) MultiSMREntry(org.corfudb.protocols.logprotocol.MultiSMREntry) SMREntry(org.corfudb.protocols.logprotocol.SMREntry)

Aggregations

SMREntry (org.corfudb.protocols.logprotocol.SMREntry)8 MultiSMREntry (org.corfudb.protocols.logprotocol.MultiSMREntry)5 MultiObjectSMREntry (org.corfudb.protocols.logprotocol.MultiObjectSMREntry)3 ILogData (org.corfudb.protocols.wireprotocol.ILogData)3 IStreamView (org.corfudb.runtime.view.stream.IStreamView)3 Test (org.junit.Test)3 TypeToken (com.google.common.reflect.TypeToken)2 CheckpointEntry (org.corfudb.protocols.logprotocol.CheckpointEntry)2 TokenResponse (org.corfudb.protocols.wireprotocol.TokenResponse)2 CorfuRuntime (org.corfudb.runtime.CorfuRuntime)2 SMRMap (org.corfudb.runtime.collections.SMRMap)2 ImmutableMap (com.google.common.collect.ImmutableMap)1 Iterators (com.google.common.collect.Iterators)1 LocalDateTime (java.time.LocalDateTime)1 java.util (java.util)1 Semaphore (java.util.concurrent.Semaphore)1 BiConsumer (java.util.function.BiConsumer)1 Consumer (java.util.function.Consumer)1 Function (java.util.function.Function)1 Getter (lombok.Getter)1