Skip to content

Commit

Permalink
refactor(message_store): move message_store to node module
Browse files Browse the repository at this point in the history
  • Loading branch information
Lorenzo Delgado committed Nov 4, 2022
1 parent 1244342 commit 4509f4f
Show file tree
Hide file tree
Showing 28 changed files with 86 additions and 319 deletions.
23 changes: 7 additions & 16 deletions apps/wakunode2/wakunode2.nim
Original file line number Diff line number Diff line change
Expand Up @@ -28,12 +28,12 @@ import
../../waku/v2/node/peer_manager/peer_store/migrations as peer_store_sqlite_migrations,
../../waku/v2/node/dnsdisc/waku_dnsdisc,
../../waku/v2/node/discv5/waku_discv5,
../../waku/v2/node/storage/migration,
../../waku/v2/node/storage/message/waku_store_queue,
../../waku/v2/node/storage/message/sqlite_store,
../../waku/v2/node/storage/message/message_retention_policy,
../../waku/v2/node/storage/message/message_retention_policy_capacity,
../../waku/v2/node/storage/message/message_retention_policy_time,
../../waku/v2/node/message_store/sqlite_store/migrations as message_store_sqlite_migrations,
../../waku/v2/node/message_store/waku_store_queue,
../../waku/v2/node/message_store/sqlite_store,
../../waku/v2/node/message_store/message_retention_policy,
../../waku/v2/node/message_store/message_retention_policy_capacity,
../../waku/v2/node/message_store/message_retention_policy_time,
../../waku/v2/node/wakuswitch,
../../waku/v2/node/waku_node,
../../waku/v2/node/waku_metrics,
Expand Down Expand Up @@ -104,15 +104,6 @@ proc performSqliteVacuum(db: SqliteDatabase): SetupResult[void] =

debug "finished sqlite database vacuuming"

proc performDbMigration(db: SqliteDatabase, migrationPath: string): SetupResult[void] =
## Run migration scripts on persistent storage
debug "starting sqlite database migration"
let migrationRes = db.migrate(migrationPath)
if migrationRes.isErr():
return err("failed to execute migration scripts: " & migrationRes.error)

debug "finished sqlite database migration"


const PeerPersistenceDbUrl = "sqlite://peers.db"

Expand Down Expand Up @@ -189,7 +180,7 @@ proc setupMessageStorage(dbUrl: string, vacuum: bool, migrate: bool): SetupResul

# Database migration
if migrate:
?performDbMigration(db.get(), migrationPath=MessageStoreMigrationPath)
?message_store_sqlite_migrations.migrate(db.get())

# TODO: Extract capacity from `messageRetentionPolicy`
return setupMessagesStore(db, storeCapacity=high(int))
Expand Down
2 changes: 1 addition & 1 deletion tests/v2/test_jsonrpc_waku.nim
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ import
libp2p/protocols/pubsub/rpc/message
import
../../waku/v1/node/rpc/hexstrings,
../../waku/v2/node/storage/message/waku_store_queue,
../../waku/v2/node/message_store/waku_store_queue,
../../waku/v2/node/waku_node,
../../waku/v2/node/jsonrpc/[store_api,
relay_api,
Expand Down
2 changes: 1 addition & 1 deletion tests/v2/test_message_store_queue.nim
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import
stew/results,
testutils/unittests
import
../../waku/v2/node/storage/message/waku_store_queue,
../../waku/v2/node/message_store/waku_store_queue,
../../waku/v2/protocol/waku_message,
../../waku/v2/protocol/waku_store,
../../waku/v2/utils/time
Expand Down
2 changes: 1 addition & 1 deletion tests/v2/test_message_store_queue_index.nim
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import
import
../../waku/v2/protocol/waku_message,
../../waku/v2/utils/time,
../../waku/v2/node/storage/message/queue_store/index,
../../waku/v2/node/message_store/queue_store/index,
./testlib/common


Expand Down
2 changes: 1 addition & 1 deletion tests/v2/test_message_store_queue_pagination.nim
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import
nimcrypto/sha2,
libp2p/protobuf/minprotobuf
import
../../waku/v2/node/storage/message/waku_store_queue,
../../waku/v2/node/message_store/waku_store_queue,
../../waku/v2/protocol/waku_store,
../../waku/v2/protocol/waku_message,
../../waku/v2/utils/time,
Expand Down
6 changes: 3 additions & 3 deletions tests/v2/test_message_store_sqlite.nim
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,9 @@ import
chronos
import
../../waku/common/sqlite,
../../waku/v2/node/storage/message/sqlite_store,
../../waku/v2/node/storage/message/message_retention_policy,
../../waku/v2/node/storage/message/message_retention_policy_capacity,
../../waku/v2/node/message_store/sqlite_store,
../../waku/v2/node/message_store/message_retention_policy,
../../waku/v2/node/message_store/message_retention_policy_capacity,
../../waku/v2/protocol/waku_message,
../../waku/v2/protocol/waku_store/pagination,
../../waku/v2/utils/time,
Expand Down
2 changes: 1 addition & 1 deletion tests/v2/test_message_store_sqlite_query.nim
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import
chronos
import
../../waku/common/sqlite,
../../waku/v2/node/storage/message/sqlite_store,
../../waku/v2/node/message_store/sqlite_store,
../../waku/v2/protocol/waku_message,
../../waku/v2/protocol/waku_store/pagination,
./utils,
Expand Down
4 changes: 2 additions & 2 deletions tests/v2/test_waku_store.nim
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@ import
libp2p/crypto/crypto
import
../../waku/common/sqlite,
../../waku/v2/node/storage/message/waku_store_queue,
../../waku/v2/node/storage/message/sqlite_store,
../../waku/v2/node/message_store/waku_store_queue,
../../waku/v2/node/message_store/sqlite_store,
../../waku/v2/node/peer_manager/peer_manager,
../../waku/v2/protocol/waku_message,
../../waku/v2/protocol/waku_store,
Expand Down
2 changes: 1 addition & 1 deletion tests/v2/test_waku_store_client.nim
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import
libp2p/crypto/crypto
import
../../waku/common/sqlite,
../../waku/v2/node/storage/message/sqlite_store,
../../waku/v2/node/message_store/sqlite_store,
../../waku/v2/node/peer_manager/peer_manager,
../../waku/v2/protocol/waku_message,
../../waku/v2/protocol/waku_store,
Expand Down
2 changes: 1 addition & 1 deletion tests/v2/test_waku_store_resume.nim
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import
libp2p/crypto/crypto
import
../../waku/common/sqlite,
../../waku/v2/node/storage/message/sqlite_store,
../../waku/v2/node/message_store/sqlite_store,
../../waku/v2/node/peer_manager/peer_manager,
../../waku/v2/protocol/waku_message,
../../waku/v2/protocol/waku_store,
Expand Down
2 changes: 1 addition & 1 deletion tests/v2/test_waku_swap.nim
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ import
import
../../waku/v2/protocol/waku_store,
../../waku/v2/protocol/waku_swap/waku_swap,
../../waku/v2/node/storage/message/waku_store_queue,
../../waku/v2/node/message_store/waku_store_queue,
../../waku/v2/node/waku_node,
../../waku/v2/utils/peers,
../test_helpers,
Expand Down
4 changes: 2 additions & 2 deletions tests/v2/test_wakunode_store.nim
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@ import
libp2p/protocols/pubsub/gossipsub
import
../../waku/common/sqlite,
../../waku/v2/node/storage/message/sqlite_store,
../../waku/v2/node/storage/message/waku_store_queue,
../../waku/v2/node/message_store/sqlite_store,
../../waku/v2/node/message_store/waku_store_queue,
../../waku/v2/protocol/waku_message,
../../waku/v2/protocol/waku_store,
../../waku/v2/protocol/waku_filter,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ else:
import
stew/results
import
../../../protocol/waku_store/message_store
../../protocol/waku_store/message_store

type RetentionPolicyResult*[T] = Result[T, string]

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import
stew/results,
chronicles
import
../../../protocol/waku_store/message_store,
../../protocol/waku_store/message_store,
./message_retention_policy

logScope:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@ import
chronicles,
chronos
import
../../../protocol/waku_store/message_store,
../../../utils/time,
../../protocol/waku_store/message_store,
../../utils/time,
./message_retention_policy

logScope:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,9 @@ import
stew/byteutils,
nimcrypto/sha2
import
../../../../protocol/waku_message,
../../../../protocol/waku_store/pagination,
../../../../utils/time
../../../protocol/waku_message,
../../../protocol/waku_store/pagination,
../../../utils/time


type Index* = object
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,11 @@ import
stew/[results, sorted_set],
chronicles
import
../../../../protocol/waku_message,
../../../../protocol/waku_store/rpc,
../../../../protocol/waku_store/pagination,
../../../../protocol/waku_store/message_store,
../../../../utils/time,
../../../protocol/waku_message,
../../../protocol/waku_store/rpc,
../../../protocol/waku_store/pagination,
../../../protocol/waku_store/message_store,
../../../utils/time,
./index


Expand Down
File renamed without changes.
38 changes: 38 additions & 0 deletions waku/v2/node/message_store/sqlite_store/migrations.nim
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
{.push raises: [].}

import
std/[tables, strutils, os],
stew/results,
chronicles
import
../../../../common/sqlite,
../../../../common/sqlite/migrations


logScope:
topics = "message_store.migration"


const SchemaVersion* = 7 # increase this when there is an update in the database schema

template projectRoot: string = currentSourcePath.rsplit(DirSep, 1)[0] / ".." / ".." / ".." / ".." / ".."
const MessageStoreMigrationPath: string = projectRoot / "migrations" / "message_store"


proc migrate*(db: SqliteDatabase, targetVersion = SchemaVersion): DatabaseResult[void] =
## Compares the `user_version` of the sqlite database with the provided `targetVersion`, then
## it runs migration scripts if the `user_version` is outdated. The `migrationScriptsDir` path
## points to the directory holding the migrations scripts once the db is updated, it sets the
## `user_version` to the `tragetVersion`.
##
## If not `targetVersion` is provided, it defaults to `SchemaVersion`.
##
## NOTE: Down migration it is not currently supported
debug "starting message store's sqlite database migration"

let migrationRes = migrations.migrate(db, targetVersion, migrationsScriptsDir=MessageStoreMigrationPath)
if migrationRes.isErr():
return err("failed to execute migration scripts: " & migrationRes.error)

debug "finished message store's sqlite database migration"
ok()
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,9 @@ import
stew/[results, byteutils],
sqlite3_abi
import
../../../../../common/sqlite,
../../../../protocol/waku_message,
../../../../utils/time
../../../../common/sqlite,
../../../protocol/waku_message,
../../../utils/time


const DbTable = "Message"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,11 @@ import
stew/[byteutils, results],
chronicles
import
../../../../../common/sqlite,
../../../../protocol/waku_message,
../../../../protocol/waku_store/pagination,
../../../../protocol/waku_store/message_store,
../../../../utils/time,
../../../../common/sqlite,
../../../protocol/waku_message,
../../../protocol/waku_store/pagination,
../../../protocol/waku_store/message_store,
../../../utils/time,
./queries

logScope:
Expand Down
91 changes: 0 additions & 91 deletions waku/v2/node/storage/message/dual_message_store.nim

This file was deleted.

Loading

0 comments on commit 4509f4f

Please sign in to comment.