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 :=
  | KVSReadRequest (KVSReadRequestMsg KVSKey)
  | KVSWrite (KVSWriteMsg KVSKey KVSDatum)
  | KVSAcquireLock (KVSAcquireLockMsg KVSKey)
  | KVSLockAcquired (KVSLockAcquiredMsg)
  | KVSRead (KVSReadMsg KVSKey KVSDatum)
  | UpdateSeenAll (UpdateSeenAllMsg);