Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: wait for index idle before returning data #389

Merged
merged 88 commits into from
Nov 28, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
88 commits
Select commit Hold shift + click to select a range
d687f1d
WIP initial work
gmaclennan Oct 26, 2023
74a77e2
rename Rpc to LocalPeers
gmaclennan Oct 26, 2023
e301c85
Handle deviceInfo internally, id -> deviceId
gmaclennan Oct 26, 2023
ae371fd
Tests for stream error handling
gmaclennan Oct 26, 2023
ccdf39f
remove unnecessary constructor
gmaclennan Oct 26, 2023
a52254b
return replication stream
gmaclennan Oct 26, 2023
50698e6
Attach protomux instance to peer info
gmaclennan Oct 26, 2023
ae35e9c
rename and re-organize
gmaclennan Oct 26, 2023
be64a3d
revert changes outside scope of PR
gmaclennan Oct 26, 2023
ee2020e
WIP initial work
gmaclennan Oct 26, 2023
0cd25da
Tie everything together
gmaclennan Oct 26, 2023
395345d
rename getProjectInstance
gmaclennan Oct 27, 2023
7963a3e
feat: client.listLocalPeers() & `local-peers` evt
gmaclennan Oct 27, 2023
9bff9ac
feat: add $sync API methods
gmaclennan Oct 27, 2023
1c0dc6b
feat: Add project.$waitForInitialSync() method
gmaclennan Oct 27, 2023
1f4fad2
Wait for initial sync within addProject()
gmaclennan Oct 27, 2023
d00bf10
fix: don't add core bitfield until core is ready
gmaclennan Oct 28, 2023
989b429
feat: expose deviceId on coreManager
gmaclennan Oct 28, 2023
bbda3f0
fix: wait for project.ready() in waitForInitialSync
gmaclennan Oct 28, 2023
0a32989
fix: skip waitForSync in tests
gmaclennan Oct 28, 2023
dc7a7c3
don't enable/disable namespace if not needed
gmaclennan Oct 30, 2023
1895679
start core download when created via sparse: false
gmaclennan Oct 30, 2023
763b57b
Add debug logging
gmaclennan Oct 30, 2023
2fb1072
fix timeout
gmaclennan Oct 30, 2023
b5f1a00
fix: Add new cores to the indexer (!!!)
gmaclennan Oct 30, 2023
d3fb8ad
remove unnecessary log stmt
gmaclennan Oct 30, 2023
32c4d32
get capabilities.getMany() to include creator
gmaclennan Oct 30, 2023
fe01caa
fix invite test
gmaclennan Oct 30, 2023
5a47b56
keep blob cores sparse
gmaclennan Oct 30, 2023
9921f66
optional param for LocalPeers
gmaclennan Nov 7, 2023
6dfa0d6
Merge branch 'main' into feat/initial-download
gmaclennan Nov 9, 2023
68455be
re-org sync and replication
gmaclennan Nov 10, 2023
7513788
update package-lock
gmaclennan Nov 10, 2023
f58bbaf
Merge branch 'main' into feat/initial-download
gmaclennan Nov 10, 2023
8c6a081
chore: Add debug logging
gmaclennan Nov 10, 2023
3bad62a
Merge branch 'chore/add-logging' into feat/initial-download
gmaclennan Nov 10, 2023
8a63746
Add new logger to discovery + dnssd
gmaclennan Nov 10, 2023
ed69a78
Get invite test working
gmaclennan Nov 10, 2023
7300da3
fix manager logger
gmaclennan Nov 11, 2023
b2eda92
cleanup invite test (and make it fail :(
gmaclennan Nov 11, 2023
2224f2b
fix: handle duplicate connections to LocalPeers
gmaclennan Nov 14, 2023
97df1c0
Merge branch 'main' into fix/local-peers
gmaclennan Nov 14, 2023
bc5e8d6
fix stream close before channel open
gmaclennan Nov 14, 2023
c1b473c
send invite to non-existent peer
gmaclennan Nov 14, 2023
07cac79
fixed fake timers implementation for tests
gmaclennan Nov 14, 2023
3407e0c
new tests for duplicate connections
gmaclennan Nov 14, 2023
6174ce0
Merge branch 'fix/local-peers' into feat/initial-download
gmaclennan Nov 14, 2023
8387f84
cleanup and small fix
gmaclennan Nov 14, 2023
6a886b8
Better state debug logging
gmaclennan Nov 14, 2023
d50fcea
chain of invites test
gmaclennan Nov 14, 2023
5bf1941
fix max listeners and add skipped test
gmaclennan Nov 14, 2023
34d2d34
fix: only request a core key from one peer
gmaclennan Nov 16, 2023
158ac7c
cleanup members tests with new helprs
gmaclennan Nov 16, 2023
687b9bc
wait for project ready when adding
gmaclennan Nov 16, 2023
e6225fe
only create 4 clients for chain of invites test
gmaclennan Nov 16, 2023
a912ede
add e2e sync tests
gmaclennan Nov 17, 2023
bbfe301
add published @mapeo/mock-data
gmaclennan Nov 20, 2023
ea442a3
fix: don't open cores in sparse mode
gmaclennan Nov 20, 2023
72f0dff
fix: option to skip auto download for tests
gmaclennan Nov 20, 2023
a07c278
e2e test for stop-start sync
gmaclennan Nov 20, 2023
800d136
fix coreManager unit tests
gmaclennan Nov 20, 2023
3afafbb
fix blob store tests
gmaclennan Nov 20, 2023
ca60188
Merge branch 'main' into feat/initial-download
gmaclennan Nov 20, 2023
420e21a
fix discovery-key event
gmaclennan Nov 20, 2023
5cd349d
add coreCount to sync state
gmaclennan Nov 20, 2023
04520f6
test sync with blocked peer & fix bugs
gmaclennan Nov 20, 2023
53e388e
fix datatype unit tests
gmaclennan Nov 20, 2023
41895a7
fix blobs server unit tests
gmaclennan Nov 20, 2023
7df2c73
remote peer-sync-controller unit test
gmaclennan Nov 20, 2023
1133e75
fix type issues caused by bad lockfile
achou11 Nov 20, 2023
5d7c251
ignore debug type errors
gmaclennan Nov 21, 2023
a2f8a1b
fixes for review comments
gmaclennan Nov 21, 2023
cd89ec4
move utils-new into utils
gmaclennan Nov 21, 2023
1f67ba8
Merge branch 'main' into feat/initial-download
gmaclennan Nov 23, 2023
83ffe92
Add debug info to test that sometimes fails
gmaclennan Nov 23, 2023
4b0c71b
Update package-lock.json version
gmaclennan Nov 23, 2023
d560d0a
remove project.ready() (breaks things)
gmaclennan Nov 24, 2023
6896021
wait for coreOwnership write before returning
gmaclennan Nov 24, 2023
aaa46f1
use file storage in tests (breaks things)
gmaclennan Nov 24, 2023
8050b2d
Catch race condition in CRUD tests
gmaclennan Nov 24, 2023
a4da0fb
fix race condition with parallel writes
gmaclennan Nov 24, 2023
a7e32b2
fix tests for new createManagers syntax
gmaclennan Nov 24, 2023
3931887
fix flakey test
gmaclennan Nov 24, 2023
19529de
fix: wait for index idle before returning data
gmaclennan Nov 25, 2023
a30943f
temp fixes to run CI
gmaclennan Nov 26, 2023
576b973
small fix for failing test
gmaclennan Nov 26, 2023
4e7604c
update to published multi-core-indexer
gmaclennan Nov 28, 2023
20c84db
Merge branch 'main' into fix/await-indexing
gmaclennan Nov 28, 2023
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 4 additions & 5 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,7 @@
"hyperswarm": "4.4.1",
"magic-bytes.js": "^1.0.14",
"map-obj": "^5.0.2",
"multi-core-indexer": "1.0.0-alpha.7",
"multi-core-indexer": "^1.0.0-alpha.9",
"p-defer": "^4.0.0",
"p-timeout": "^6.1.2",
"patch-package": "^8.0.0",
Expand Down
2 changes: 1 addition & 1 deletion src/core-ownership.js
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ export class CoreOwnership {
expressions.push(eq(table[`${namespace}CoreId`], coreId))
}
// prettier-ignore
const result = this.#dataType[kSelect]()
const result = (await this.#dataType[kSelect]())
.where(or.apply(null, expressions))
.get()
if (!result) {
Expand Down
4 changes: 4 additions & 0 deletions src/datastore/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,10 @@ export class DataStore extends TypedEmitter {
})
}

get indexer() {
return this.#coreIndexer
}

get namespace() {
return this.#namespace
}
Expand Down
7 changes: 6 additions & 1 deletion src/datatype/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -140,6 +140,7 @@ export class DataType {
* @param {string} docId
*/
async getByDocId(docId) {
await this.#dataStore.indexer.idle()
const result = this.#sql.getByDocId.get({ docId })
if (!result) throw new Error('Not found')
return deNullify(result)
Expand All @@ -151,6 +152,7 @@ export class DataType {
}

async getMany() {
await this.#dataStore.indexer.idle()
return this.#sql.getMany.all().map((doc) => deNullify(doc))
}

Expand All @@ -161,6 +163,7 @@ export class DataType {
* @param {T} value
*/
async update(versionId, value) {
await this.#dataStore.indexer.idle()
const links = Array.isArray(versionId) ? versionId : [versionId]
const { docId, createdAt, createdBy } = await this.#validateLinks(links)
/** @type {any} */
Expand All @@ -181,6 +184,7 @@ export class DataType {
* @param {string | string[]} versionId
*/
async delete(versionId) {
await this.#dataStore.indexer.idle()
const links = Array.isArray(versionId) ? versionId : [versionId]
const { docId, createdAt, createdBy } = await this.#validateLinks(links)
/** @type {any} */
Expand All @@ -200,7 +204,8 @@ export class DataType {
/**
* @param {Parameters<import('drizzle-orm/better-sqlite3').BetterSQLite3Database['select']>[0]} fields
*/
[kSelect](fields) {
async [kSelect](fields) {
await this.#dataStore.indexer.idle()
return this.#db.select(fields).from(this.#table)
}

Expand Down
4 changes: 3 additions & 1 deletion test-e2e/manager-basic.js
Original file line number Diff line number Diff line change
Expand Up @@ -280,7 +280,9 @@ test('Consistent storage folders', async (t) => {
},
{ waitForSync: false }
)
await manager.getProject(projectId)
const project = await manager.getProject(projectId)
// awaiting this ensures that indexing is done, which means that indexer storage is created
await project.$getOwnCapabilities()
}

// @ts-ignore snapshot() is missing from typedefs
Expand Down
8 changes: 6 additions & 2 deletions test-e2e/sync.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,8 @@ import { BLOCKED_ROLE_ID, COORDINATOR_ROLE_ID } from '../src/capabilities.js'

const SCHEMAS_INITIAL_SYNC = ['preset', 'field']

test('Create and sync data', async function (t) {
const COUNT = 5
test('Create and sync data', { timeout: 100_000 }, async function (t) {
const COUNT = 10
const managers = await createManagers(COUNT, t)
const [invitor, ...invitees] = managers
const disconnect = connectPeers(managers, { discovery: false })
Expand Down Expand Up @@ -252,5 +252,9 @@ test('no sync capabilities === no namespaces sync apart from auth', async (t) =>
t.alike(invitorState[ns].localState, inviteeState[ns].localState)
}

// Temp fix until we have .close() method - waits for indexing idle to ensure
// we don't close storage in teardown while index is still being written.
await Promise.all(projects.map((p) => p.$getProjectSettings()))
gmaclennan marked this conversation as resolved.
Show resolved Hide resolved

await disconnect1()
})
2 changes: 1 addition & 1 deletion test-e2e/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import { randomInt } from 'node:crypto'
import { temporaryDirectory } from 'tempy'
import fsPromises from 'node:fs/promises'

const FAST_TESTS = true
const FAST_TESTS = !!process.env.FAST_TESTS
const projectMigrationsFolder = new URL('../drizzle/project', import.meta.url)
.pathname
const clientMigrationsFolder = new URL('../drizzle/client', import.meta.url)
Expand Down
4 changes: 0 additions & 4 deletions tests/datastore.js
Original file line number Diff line number Diff line change
Expand Up @@ -100,10 +100,6 @@ test('index events', async (t) => {
await dataStore.write(obs)
await idlePromise
const expectedStates = [
{
current: 'idle',
remaining: 0,
},
{
current: 'indexing',
remaining: 1,
Expand Down
Loading