module arch.node.engines.shard_messages;

import prelude open;
import arch.node.types.basics open;
import arch.node.types.identities open;

type KVSReadRequestMsg KVSKey :=
  mkKVSReadRequestMsg@{
    timestamp : TxFingerprint;
    key : KVSKey;
    actual : Bool;
  };

type KVSWriteMsg KVSKey KVSDatum :=
  mkKVSWriteMsg@{
    timestamp : TxFingerprint;
    key : KVSKey;
    datum : Option KVSDatum;
  };

type UpdateSeenAllMsg :=
  mkUpdateSeenAllMsg@{
    timestamp : TxFingerprint;
    write : Bool;
  };

type KVSAcquireLockMsg KVSKey :=
  mkKVSAcquireLockMsg@{
    lazy_read_keys : Set KVSKey;
    eager_read_keys : Set KVSKey;
    will_write_keys : Set KVSKey;
    may_write_keys : Set KVSKey;
    worker : EngineID;
    executor : EngineID;
    timestamp : TxFingerprint;
  };

type KVSLockAcquiredMsg :=
  mkKVSLockAcquiredMsg@{
    timestamp : TxFingerprint;
  };

type KVSReadMsg KVSKey KVSDatum :=
  mkKVSReadMsg@{
    timestamp : TxFingerprint;
    key : KVSKey;
    data : KVSDatum;
  };

type ShardMsg KVSKey KVSDatum :=
  | ShardMsgKVSReadRequest (KVSReadRequestMsg KVSKey)
  | ShardMsgKVSWrite (KVSWriteMsg KVSKey KVSDatum)
  | ShardMsgKVSAcquireLock (KVSAcquireLockMsg KVSKey)
  | ShardMsgKVSLockAcquired (KVSLockAcquiredMsg)
  | ShardMsgKVSRead (KVSReadMsg KVSKey KVSDatum)
  | ShardMsgUpdateSeenAll (UpdateSeenAllMsg);