-
Notifications
You must be signed in to change notification settings - Fork 285
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: add crash recovery and knex config for production
Signed-off-by: Yogesh01000100 <yogeshone678@gmail.com> chore(satp-hermes): improve DB management Signed-off-by: Rafael Belchior <rafael.belchior@tecnico.ulisboa.pt> chore(satp-hermes): crash recovery architecture Signed-off-by: Rafael Belchior <rafael.belchior@tecnico.ulisboa.pt> fix(recovery): enhance crash recovery and rollback implementation Signed-off-by: Yogesh01000100 <yogeshone678@gmail.com> refactor(recovery): consolidate logic and improve SATP message handling Signed-off-by: Yogesh01000100 <yogeshone678@gmail.com> feat(recovery): add rollback implementations Signed-off-by: Yogesh01000100 <yogeshone678@gmail.com> fix: correct return types and inits Signed-off-by: Yogesh01000100 <yogeshone678@gmail.com>
- Loading branch information
1 parent
47bc45e
commit 21ad772
Showing
34 changed files
with
1,963 additions
and
103 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
version: '3.8' | ||
services: | ||
db: | ||
image: postgres:13 | ||
environment: | ||
POSTGRES_DB: ${DB_NAME} | ||
POSTGRES_USER: ${DB_USER} | ||
POSTGRES_PASSWORD: ${DB_PASSWORD} | ||
POSTGRES_HOST: ${DB_HOST} | ||
PGPORT: ${DB_PORT} | ||
ports: | ||
- "${DB_PORT}:5432" | ||
volumes: | ||
- pgdata:/var/lib/postgresql/data | ||
|
||
volumes: | ||
pgdata: |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,16 +1,34 @@ | ||
import path from "path"; | ||
import { v4 as uuidv4 } from "uuid"; | ||
import dotenv from "dotenv"; | ||
|
||
dotenv.config({ path: path.resolve(__dirname, "../../.env") }); | ||
|
||
// default configuration for knex | ||
module.exports = { | ||
development: { | ||
client: "sqlite3", | ||
connection: { | ||
filename: path.resolve(__dirname, ".dev-" + uuidv4() + ".sqlite3"), | ||
filename: path.join(__dirname, "data", "/.dev-" + uuidv4() + ".sqlite3"), | ||
}, | ||
migrations: { | ||
directory: path.resolve(__dirname, "migrations"), | ||
}, | ||
seeds: { | ||
directory: path.resolve(__dirname, "seeds"), | ||
}, | ||
useNullAsDefault: true, | ||
}, | ||
production: { | ||
client: "pg", | ||
connection: { | ||
host: process.env.DB_HOST, | ||
port: process.env.DB_PORT, | ||
user: process.env.DB_USER, | ||
password: process.env.DB_PASSWORD, | ||
database: process.env.DB_NAME, | ||
}, | ||
migrations: { | ||
directory: path.resolve(__dirname, "migrations"), | ||
}, | ||
}, | ||
}; |
15 changes: 0 additions & 15 deletions
15
packages/cactus-plugin-satp-hermes/src/knex/migrations/20220331132128_create_logs_table.js
This file was deleted.
Oops, something went wrong.
16 changes: 16 additions & 0 deletions
16
packages/cactus-plugin-satp-hermes/src/knex/migrations/20220331132128_create_logs_table.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
import { Knex } from "knex"; | ||
|
||
export function up(knex: Knex): Knex.SchemaBuilder { | ||
return knex.schema.createTable("logs", (table) => { | ||
table.string("sessionID").notNullable(); | ||
table.string("type").notNullable(); | ||
table.string("key").notNullable().primary(); | ||
table.string("operation").notNullable(); | ||
table.string("timestamp").notNullable(); | ||
table.string("data").notNullable(); | ||
}); | ||
} | ||
|
||
export function down(knex: Knex): Knex.SchemaBuilder { | ||
return knex.schema.dropTable("logs"); | ||
} |
13 changes: 0 additions & 13 deletions
13
.../cactus-plugin-satp-hermes/src/knex/migrations/20240130234303_create_remote_logs_table.js
This file was deleted.
Oops, something went wrong.
14 changes: 14 additions & 0 deletions
14
.../cactus-plugin-satp-hermes/src/knex/migrations/20240130234303_create_remote_logs_table.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
import { Knex } from "knex"; | ||
|
||
export async function up(knex: Knex): Promise<void> { | ||
return knex.schema.createTable("remote-logs", (table) => { | ||
table.string("hash").notNullable(); | ||
table.string("signature").notNullable(); | ||
table.string("signerPubKey").notNullable(); | ||
table.string("key").notNullable().primary(); | ||
}); | ||
} | ||
|
||
export async function down(knex: Knex): Promise<void> { | ||
return knex.schema.dropTable("remote-logs"); | ||
} |
35 changes: 35 additions & 0 deletions
35
packages/cactus-plugin-satp-hermes/src/knex/seeds/1724235145_create_dummy_entries.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
// 20240821000000_seed_dev_logs.ts | ||
|
||
import { Knex } from "knex"; | ||
|
||
export async function seed(knex: Knex): Promise<void> { | ||
// Check if we're in the development environment | ||
if (process.env.NODE_ENV !== "development") { | ||
console.log("Skipping seed: Not in development environment"); | ||
return; | ||
} | ||
|
||
// Function to clear table if it exists | ||
async function clearTableIfExists(tableName: string) { | ||
if (await knex.schema.hasTable(tableName)) { | ||
await knex(tableName).del(); | ||
console.log(`Cleared existing entries from ${tableName}`); | ||
} else { | ||
console.log(`Table ${tableName} does not exist, skipping clear`); | ||
} | ||
} | ||
|
||
// Clear existing entries if tables exist | ||
await clearTableIfExists("logs"); | ||
await clearTableIfExists("remote-logs"); | ||
|
||
// Insert a single deterministic log entry | ||
await knex("logs").insert({ | ||
sessionID: "test-session-001", | ||
type: "info", | ||
key: "test-log-001", | ||
operation: "create", | ||
timestamp: "2024-08-21T12:00:00Z", | ||
data: JSON.stringify({ message: "This is a test log entry" }), | ||
}); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 2 additions & 0 deletions
2
...ages/cactus-plugin-satp-hermes/src/main/typescript/blo/recover/recover-handler-service.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
// handler to allow a user application to communicate a gateway it crashed and needs to be recovered. It "forces" and update of status with a counterparty gateway | ||
// TODO update the spec with a RecoverForce message that is handled by this handler |
2 changes: 2 additions & 0 deletions
2
...ges/cactus-plugin-satp-hermes/src/main/typescript/blo/recover/rollback-handler-service.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
// handler to allow a user application to force a rollback | ||
// TODO update the spec with RollbackForce message that is handled by this handler |
Oops, something went wrong.