Skip to content

Commit

Permalink
sql: clean up Raft engine
Browse files Browse the repository at this point in the history
  • Loading branch information
erikgrinaker committed Jun 18, 2024
1 parent 969c9a5 commit 2f1905c
Show file tree
Hide file tree
Showing 5 changed files with 235 additions and 236 deletions.
6 changes: 4 additions & 2 deletions src/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -42,8 +42,10 @@ impl Error {
/// panic to prevent replica divergence.
pub fn is_deterministic(&self) -> bool {
match self {
// Aborts don't happen during application, only leader changes.
Error::Abort => true,
// Aborts don't happen during application, only leader changes. But
// we consider them non-deterministic in case a abort should happen
// unexpectedly below Raft.
Error::Abort => false,
// Possible data corruption local to this node.
Error::InvalidData(_) => false,
// Input errors are (likely) deterministic. We could employ command
Expand Down
5 changes: 5 additions & 0 deletions src/raft/message.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,11 @@ impl encoding::Value for Envelope {}
/// ensuring messages are not dropped or reordered as long as the connection
/// remains intact. A message and its response are sent across separate TCP
/// connections (outbound from their respective senders).
///
/// TODO: add a Read(Response) message type for reads, to avoid sending
/// heartbeats on every read -- these could otherwise cause spurious replication
/// probes for behind followers. We still need the read_seq in the heartbeat for
/// retries.
#[derive(Clone, Debug, PartialEq, Serialize, Deserialize)]
pub enum Message {
/// Candidates campaign for leadership by soliciting votes from peers.
Expand Down
8 changes: 3 additions & 5 deletions src/sql/engine/engine.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,11 +20,11 @@ pub trait Engine<'a>: Sized {
type Transaction: Transaction + Catalog + 'a;

/// Begins a read-write transaction.
fn begin(&self) -> Result<Self::Transaction>;
fn begin(&'a self) -> Result<Self::Transaction>;
/// Begins a read-only transaction.
fn begin_read_only(&self) -> Result<Self::Transaction>;
fn begin_read_only(&'a self) -> Result<Self::Transaction>;
/// Begins a read-only transaction as of a historical version.
fn begin_as_of(&self, version: mvcc::Version) -> Result<Self::Transaction>;
fn begin_as_of(&'a self, version: mvcc::Version) -> Result<Self::Transaction>;

/// Creates a session for executing SQL statements. Can't outlive engine.
fn session(&'a self) -> Session<'a, Self> {
Expand All @@ -38,8 +38,6 @@ pub trait Engine<'a>: Sized {
/// All methods operate on row batches rather than single rows to amortize the
/// cost. With the Raft engine, each call results in a Raft roundtrip, and we'd
/// rather not have to do that for every single row that's modified.
///
/// TODO: decide whether to use borrowed, owned, or Cowed parameters.
pub trait Transaction {
/// The transaction's MVCC version. Unique for read/write transactions.
fn version(&self) -> mvcc::Version;
Expand Down
8 changes: 4 additions & 4 deletions src/sql/engine/local.rs
Original file line number Diff line number Diff line change
Expand Up @@ -31,13 +31,13 @@ impl<E: storage::Engine> Local<E> {
Ok(<Self as super::Engine>::Transaction::new(self.kv.resume(state)?))
}

/// Fetches an unversioned metadata value
pub fn get_metadata(&self, key: &[u8]) -> Result<Option<Vec<u8>>> {
/// Fetches an unversioned key.
pub fn get_unversioned(&self, key: &[u8]) -> Result<Option<Vec<u8>>> {
self.kv.get_unversioned(key)
}

/// Sets an unversioned metadata value
pub fn set_metadata(&self, key: &[u8], value: Vec<u8>) -> Result<()> {
/// Sets an unversioned key.
pub fn set_unversioned(&self, key: &[u8], value: Vec<u8>) -> Result<()> {
self.kv.set_unversioned(key, value)
}
}
Expand Down
Loading

0 comments on commit 2f1905c

Please sign in to comment.