purge unused schema features

This commit is contained in:
Arya Irani 2021-05-06 21:21:52 -06:00
parent cfbc676fa2
commit ec87b8e6f4
6 changed files with 31 additions and 52 deletions

View File

@ -34,19 +34,8 @@ newtype BranchHashId = BranchHashId { unBranchHashId :: HashId } deriving (Eq, O
newtype CausalHashId = CausalHashId { unCausalHashId :: HashId } deriving (Eq, Ord)
deriving (Num, Real, Enum, Integral, Bits, Hashable, FromField, ToField) via HashId
newtype TypeId = TypeId ObjectId deriving Show deriving (FromField, ToField) via ObjectId
newtype TermId = TermCycleId ObjectId deriving Show deriving (FromField, ToField) via ObjectId
newtype DeclId = DeclCycleId ObjectId deriving Show deriving (FromField, ToField) via ObjectId
-- |For generational garbage-collection; 0 is the oldest generation.
newtype Generation = Generation { unGeneration :: Word64 }
deriving (Eq, Ord, Show)
deriving (Enum, FromField, ToField) via Word64
-- |Also I guess garbage-collection related? 🤔
newtype Committed = Committed { unCommitted :: Bool }
deriving (Eq, Ord, Show)
deriving (Enum, FromField, ToField) via Bool
newtype SchemaVersion = SchemaVersion Word64 deriving (Eq, Ord, Show)
deriving (Num, Real, Enum, Integral, Bits, Hashable, FromField, ToField) via Word64
instance Show PatchObjectId where
show h = "PatchObjectId (" ++ show (unPatchObjectId h) ++ ")"

View File

@ -32,7 +32,7 @@ import Data.Int (Int8)
import qualified Data.List.Extra as List
import Data.List.NonEmpty (NonEmpty)
import qualified Data.List.NonEmpty as Nel
import Data.Maybe (fromJust, fromMaybe)
import Data.Maybe (fromJust)
import Data.String (fromString)
import Data.String.Here.Uninterpolated (here, hereFile)
import Data.Text (Text)
@ -55,8 +55,6 @@ import U.Codebase.Sqlite.DbId
( BranchHashId (..),
BranchObjectId (..),
CausalHashId (..),
Committed (..),
Generation (..),
HashId (..),
ObjectId (..),
TextId,
@ -153,7 +151,6 @@ checkForMissingSchema = filterM missing schema
("index", "object_type_id"),
("table", "causal"),
("index", "causal_value_hash_id"),
("index", "causal_gc_generation"),
("table", "namespace_root"),
("table", "causal_parent"),
("index", "causal_parent_causal_id"),
@ -335,23 +332,28 @@ updateObjectBlob oId bs = execute sql (oId, bs) where sql = [here|
-- |Maybe we would generalize this to something other than NamespaceHash if we
-- end up wanting to store other kinds of Causals here too.
saveCausal :: DB m => CausalHashId -> BranchHashId -> m ()
saveCausal self value = execute sql (self, value, Committed True, Generation 0) where sql = [here|
INSERT INTO causal (self_hash_id, value_hash_id, commit_flag, gc_generation)
VALUES (?, ?, ?, ?)
saveCausal self value = execute sql (self, value) where sql = [here|
INSERT INTO causal (self_hash_id, value_hash_id)
VALUES (?, ?)
ON CONFLICT DO NOTHING
|]
-- saveCausal self value = execute sql (self, value, Committed True, Generation 0) where sql = [here|
-- INSERT INTO causal (self_hash_id, value_hash_id, commit_flag, gc_generation)
-- VALUES (?, ?, ?, ?)
-- ON CONFLICT DO NOTHING
-- |]
-- maybe: look at whether parent causal is "committed"; if so, then increment;
-- otherwise, don't.
getNurseryGeneration :: DB m => m Generation
getNurseryGeneration = query_ sql <&> \case
[] -> Generation 0
[fromOnly -> g] -> Generation $ fromMaybe 0 g
(fmap fromOnly -> gs) ->
error $ "How did I get multiple values out of a MAX()? " ++ show gs
where sql = [here|
SELECT MAX(gc_generation) FROM causal;
|]
-- -- maybe: look at whether parent causal is "committed"; if so, then increment;
-- -- otherwise, don't.
-- getNurseryGeneration :: DB m => m Generation
-- getNurseryGeneration = query_ sql <&> \case
-- [] -> Generation 0
-- [fromOnly -> g] -> Generation $ fromMaybe 0 g
-- (fmap fromOnly -> gs) ->
-- error $ "How did I get multiple values out of a MAX()? " ++ show gs
-- where sql = [here|
-- SELECT MAX(gc_generation) FROM causal;
-- |]
loadCausalValueHashId :: EDB m => CausalHashId -> m BranchHashId
loadCausalValueHashId chId@(CausalHashId id) =

View File

@ -102,8 +102,7 @@ sync22 = do
hCache <- Cache.semispaceCache size
oCache <- Cache.semispaceCache size
cCache <- Cache.semispaceCache size
gc <- runDest $ Q.getNurseryGeneration
pure $ Sync (trySync tCache hCache oCache cCache (succ gc))
pure $ Sync (trySync tCache hCache oCache cCache)
trySync ::
forall m.
@ -112,10 +111,9 @@ trySync ::
Cache m HashId HashId ->
Cache m ObjectId ObjectId ->
Cache m CausalHashId CausalHashId ->
Generation ->
Entity ->
m (TrySyncResult Entity)
trySync tCache hCache oCache cCache _gc = \case
trySync tCache hCache oCache cCache = \case
-- for causals, we need to get the value_hash_id of the thingo
-- - maybe enqueue their parents
-- - enqueue the self_ and value_ hashes

View File

@ -89,12 +89,9 @@ CREATE INDEX object_type_id ON object(type_id);
-- `commit_flag` and `gc_generation` are basically unused at the moment.
CREATE TABLE causal (
self_hash_id INTEGER PRIMARY KEY NOT NULL CONSTRAINT causal_fk1 REFERENCES hash(id),
value_hash_id INTEGER NOT NULL CONSTRAINT causal_fk2 REFERENCES hash(id),
commit_flag INTEGER NOT NULL,
gc_generation INTEGER NOT NULL
value_hash_id INTEGER NOT NULL CONSTRAINT causal_fk2 REFERENCES hash(id)
);
CREATE INDEX causal_value_hash_id ON causal(value_hash_id);
CREATE INDEX causal_gc_generation ON causal(gc_generation);
-- We expect exactly 1 row, which we overwrite when we setRootNamespace.
CREATE TABLE namespace_root (

View File

@ -17,19 +17,17 @@ The object table stores things that are identified by hash and represented with
```sql
CREATE TABLE causal (
self_hash_id INTEGER PRIMARY KEY NOT NULL CONSTRAINT causal_fk1 REFERENCES hash(id),
value_hash_id INTEGER NOT NULL CONSTRAINT causal_fk2 REFERENCES hash(id),
commit_flag INTEGER NOT NULL,
gc_generation INTEGER NOT NULL
self_hash_id INTEGER PRIMARY KEY NOT NULL REFERENCES hash(id),
value_hash_id INTEGER NOT NULL REFERENCES hash(id)
);
CREATE TABLE causal_parent (
causal_id INTEGER NOT NULL REFERENCES causal(self_hash_id),
parent_id INTEGER NOT NULL REFERENCES causal(self_hash_id),
parent_id INTEGER NOT NULL REFERENCES causal(self_hash_id)
);
```
Although causals are indexed by `hash.id`, an entry in the `causal` table is required, to qualify as a real causal. This also tells us the hash of its root namespace slice (which may or may not be present), whether it's been committed, and its `gc_generation`, which will be `True` and `0` until a commit/squash feature is implemented.
Although causals are indexed by `hash.id`, an entry in the `causal` table is required, to qualify as a real causal. This also tells us the hash of its root namespace slice (which may or may not be present).
**Hash-based vs Object-based References**

View File

@ -37,8 +37,6 @@ import Database.SQLite.Simple (Connection)
import Debug.Trace (traceM)
import System.IO (stdout)
import System.IO.Extra (hFlush)
import U.Codebase.Sqlite.DbId (Generation)
import qualified U.Codebase.Sqlite.Queries as Q
import U.Codebase.Sync (Sync (Sync), TrySyncResult)
import qualified U.Codebase.Sync as Sync
import qualified U.Util.Monoid as Monoid
@ -143,9 +141,7 @@ sync12 ::
(MonadIO f, MonadReader (Env p x) f, RS m n a, Applicative m) =>
(m ~> n) ->
f (Sync n (Entity m))
sync12 t = do
gc <- runDest' Q.getNurseryGeneration
pure $ Sync (trySync t (succ gc))
sync12 t = pure $ Sync (trySync t)
-- For each entity, we have to check to see
-- a) if it exists (if not, mark as missing in Status)
@ -159,10 +155,9 @@ trySync ::
forall m n a.
(R m n a, S m n, Applicative m) =>
(m ~> n) ->
Generation ->
Entity m ->
n (TrySyncResult (Entity m))
trySync t _gc e = do
trySync t e = do
Env _ dest _ <- Reader.ask
case e of
C h mc -> do