Search in sources :

Example 1 with PaxosState

use of org.apache.cassandra.service.paxos.PaxosState in project cassandra by apache.

the class SystemKeyspace method loadPaxosState.

public static PaxosState loadPaxosState(DecoratedKey key, TableMetadata metadata, int nowInSec) {
    String req = "SELECT * FROM system.%s WHERE row_key = ? AND cf_id = ?";
    UntypedResultSet results = QueryProcessor.executeInternalWithNow(nowInSec, System.nanoTime(), format(req, PAXOS), key.getKey(), metadata.id.asUUID());
    if (results.isEmpty())
        return new PaxosState(key, metadata);
    UntypedResultSet.Row row = results.one();
    Commit promised = row.has("in_progress_ballot") ? new Commit(row.getUUID("in_progress_ballot"), new PartitionUpdate(metadata, key, metadata.regularAndStaticColumns(), 1)) : Commit.emptyCommit(key, metadata);
    // either we have both a recently accepted ballot and update or we have neither
    Commit accepted = row.has("proposal_version") && row.has("proposal") ? new Commit(row.getUUID("proposal_ballot"), PartitionUpdate.fromBytes(row.getBytes("proposal"), row.getInt("proposal_version"))) : Commit.emptyCommit(key, metadata);
    // either most_recent_commit and most_recent_commit_at will both be set, or neither
    Commit mostRecent = row.has("most_recent_commit_version") && row.has("most_recent_commit") ? new Commit(row.getUUID("most_recent_commit_at"), PartitionUpdate.fromBytes(row.getBytes("most_recent_commit"), row.getInt("most_recent_commit_version"))) : Commit.emptyCommit(key, metadata);
    return new PaxosState(promised, accepted, mostRecent);
}
Also used : UntypedResultSet(org.apache.cassandra.cql3.UntypedResultSet) PaxosState(org.apache.cassandra.service.paxos.PaxosState) Commit(org.apache.cassandra.service.paxos.Commit) PartitionUpdate(org.apache.cassandra.db.partitions.PartitionUpdate)

Aggregations

UntypedResultSet (org.apache.cassandra.cql3.UntypedResultSet)1 PartitionUpdate (org.apache.cassandra.db.partitions.PartitionUpdate)1 Commit (org.apache.cassandra.service.paxos.Commit)1 PaxosState (org.apache.cassandra.service.paxos.PaxosState)1