Skip to content

Commit 31655c3

Browse files
committed
Fix up some queries
1 parent cd9ce0e commit 31655c3

File tree

6 files changed

+16
-9
lines changed

6 files changed

+16
-9
lines changed

codebase2/codebase-sqlite/U/Codebase/Sqlite/Queries.hs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -418,7 +418,7 @@ type TextPathSegments = [Text]
418418
-- * main squeeze
419419

420420
currentSchemaVersion :: SchemaVersion
421-
currentSchemaVersion = 22
421+
currentSchemaVersion = 23
422422

423423
runCreateSql :: Transaction ()
424424
runCreateSql =
@@ -4039,6 +4039,7 @@ streamTempEntitiesSyncV3 rootCausalHash action = do
40394039
Sqlite.queryStreamRow @(Hash32, BL.ByteString)
40404040
[sql|
40414041
SELECT entity_hash, entity_data
4042+
FROM syncv3_temp_entity
40424043
WHERE root_causal = :rootCausalHash
40434044
ORDER BY entity_depth ASC
40444045
|]

codebase2/codebase-sqlite/sql/020-add-sync-v3-temp-tables.sql

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
-- Add a new table for storing entities which are currently being synced
22

33
CREATE TABLE syncv3_temp_entity (
4-
root_causal INTEGER NOT NULL REFERENCES hash (id) ON DELETE CASCADE,
4+
root_causal INTEGER NOT NULL,
55
entity_hash TEXT NOT NULL,
66
entity_kind TEXT NOT NULL,
77
entity_data BLOB NOT NULL,

unison-cli/package.yaml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,7 @@ library:
5353
- megaparsec
5454
- memory
5555
- mtl
56+
- network
5657
- network-simple
5758
- network-uri
5859
- nonempty-containers

unison-cli/src/Unison/Share/SyncV3.hs

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -108,7 +108,7 @@ syncFromCodeserver _shouldValidate codeserver branchRef hashJwt = do
108108
-- TODO: proper error handling
109109
Left err -> error $ show err
110110
Right () -> pure ()
111-
Debug.debugLogM Debug.Temp "Done sync, flushing temp entities"
111+
Debug.debugLogM Debug.Temp "!Done sync, flushing temp entities"
112112
causalId <- liftIO $ flushTemp codebase (Share.hashJWTHash hashJwt)
113113
pure $ Right (Sync.hash32ToCausalHash rootCausalHash, causalId)
114114

@@ -129,11 +129,16 @@ doSync codebase SyncState {pendingRequestsVar, yetToRequestVar, toIngestQueue, r
129129
_ <- Ki.fork scope (receiverWorker onErr)
130130
_ <- Ki.fork scope (requesterWorker onErr)
131131
_ <- Ki.fork scope (ingestionWorker onErr)
132+
let finished = do
133+
pending <- readTVar pendingRequestsVar
134+
yetToReq <- readTVar yetToRequestVar
135+
guard $ Set.null pending && Set.null yetToReq
132136

133137
Debug.debugLogM Debug.Temp "Awaiting completion"
134138
result <-
135139
atomically $
136-
(Right <$> Ki.awaitAll scope)
140+
(Right <$> finished)
141+
<|> (Right <$> Ki.awaitAll scope)
137142
<|> (Left . Left <$> readTMVar errorVar)
138143
<|> (Left . Right <$> connectionClosed)
139144

@@ -159,6 +164,7 @@ doSync codebase SyncState {pendingRequestsVar, yetToRequestVar, toIngestQueue, r
159164
Debug.debugLogM Debug.Temp "Requester waiting to send requests"
160165
atomically $ do
161166
requests <- readTVar yetToRequestVar
167+
guard $ not (Set.null requests)
162168
writeTVar yetToRequestVar Set.empty
163169
modifyTVar' pendingRequestsVar (Set.union requests)
164170
send $ Msg $ ReceiverEntityRequest $ EntityRequestMsg (Set.toList requests)
@@ -211,11 +217,14 @@ flushTemp codebase rootCausalHash = do
211217
Nothing -> pure ()
212218
Just (hash, tempEntityBytes) ->
213219
do
220+
Debug.debugLogM Debug.Temp $ "Flushing temp entity: " <> show hash
214221
tempEntity <- case CBOR.deserialiseOrFailCBORBytes (CBOR.CBORBytes tempEntityBytes) of
215222
-- TODO: proper error handling
216223
Left err -> error $ show err
217224
Right tempEntity -> pure tempEntity
225+
Debug.debugLogM Debug.Temp $ "Saving in main" <> show hash
218226
void $ Q.saveTempEntityInMain v2HashHandle hash tempEntity
219227
loop
220228
loop
229+
Debug.debugLogM Debug.Temp "Flushed temp entities, getting causal hash id"
221230
Q.expectCausalHashIdByCausalHash (Sync.hash32ToCausalHash rootCausalHash)

unison-cli/unison-cli.cabal

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -248,6 +248,7 @@ library
248248
, megaparsec
249249
, memory
250250
, mtl
251+
, network
251252
, network-simple
252253
, network-uri
253254
, nonempty-containers

unison-share-api/src/Unison/SyncV3/Types.hs

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,6 @@ import Network.WebSockets (WebSocketsData)
2828
import Network.WebSockets qualified as WS
2929
import U.Codebase.Sqlite.Orphans ()
3030
import U.Codebase.Sqlite.TempEntity
31-
import Unison.Debug qualified as Debug
3231
import Unison.Hash32 (Hash32)
3332
import Unison.Prelude (tShow)
3433
import Unison.Server.Orphans ()
@@ -97,7 +96,6 @@ instance CBOR.Serialise FromReceiverMessageTag where
9796

9897
decode = do
9998
tag <- CBOR.decode @Int
100-
Debug.debugM Debug.Temp "Decoding FromReceiverMessageTag with tag" tag
10199
case tag of
102100
0 -> pure ReceiverInitStreamTag
103101
1 -> pure ReceiverEntityRequestTag
@@ -120,7 +118,6 @@ instance (ToJSON ah, FromJSON ah) => CBOR.Serialise (InitMsg ah) where
120118
CBOR.encode @BS.ByteString $ BL.toStrict $ Aeson.encode msg
121119

122120
decode = do
123-
Debug.debugLogM Debug.Temp "Decoding InitMsg from JSON via CBOR"
124121
bs <- CBOR.decode @BS.ByteString
125122
case Aeson.eitherDecode $ BL.fromStrict bs of
126123
Left err -> fail $ "Error decoding InitMsg from JSON: " <> err
@@ -147,7 +144,6 @@ instance (CBOR.Serialise h, ToJSON ah, FromJSON ah) => CBOR.Serialise (FromRecei
147144
<> CBOR.encode msg
148145
decode = do
149146
tag <- CBOR.decode @FromReceiverMessageTag
150-
Debug.debugM Debug.Temp "Decoding FromReceiverMessage with tag" tag
151147
case tag of
152148
ReceiverInitStreamTag -> ReceiverInitStream <$> CBOR.decode @(InitMsg ah)
153149
ReceiverEntityRequestTag -> ReceiverEntityRequest <$> CBOR.decode @(EntityRequestMsg h)
@@ -367,7 +363,6 @@ instance (CBOR.Serialise a, CBOR.Serialise err) => CBOR.Serialise (MsgOrError er
367363

368364
decode = do
369365
tag <- CBOR.decode @Int
370-
Debug.debugM Debug.Temp "Decoding MsgOrError with tag" tag
371366
case tag of
372367
0 -> Msg <$> CBOR.decode
373368
1 -> Err <$> CBOR.decode

0 commit comments

Comments
 (0)