Skip to content

Commit

Permalink
feat(db): add config option to support disabling DB writers #37
Browse files Browse the repository at this point in the history
Adds an experimental config environment variable, START_WRITERS. It
defaults to 'true'. If set to 'false', worker processes that write to
the DB will be disabled. This is to support experimentation with SQLite
replaction via LiteFS.
  • Loading branch information
djwhitt committed Aug 25, 2023
1 parent 795b7f7 commit 44add3e
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 11 deletions.
1 change: 1 addition & 0 deletions docker-compose.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -48,3 +48,4 @@ services:
- ANS104_INDEX_FILTER=${ANS104_INDEX_FILTER:-}
- ARNS_ROOT_HOST=${ARNS_ROOT_HOST:-}
- SANDBOX_PROTOCOL=${SANDBOX_PROTOCOL:-}
- START_WRITERS=${START_WRITERS:-}
10 changes: 7 additions & 3 deletions src/app.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,9 +37,13 @@ import { apolloServer } from './routes/graphql/index.js';
import * as system from './system.js';

system.arweaveClient.refreshPeers();
system.blockImporter.start();
system.txRepairWorker.start();
system.bundleRepairWorker.start();

// Allow starting without writers to support SQLite replication
if (config.START_WRITERS) {
system.blockImporter.start();
system.txRepairWorker.start();
system.bundleRepairWorker.start();
}

// HTTP server
const app = express();
Expand Down
2 changes: 2 additions & 0 deletions src/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -71,3 +71,5 @@ export const ANS104_INDEX_FILTER = createFilter(
);
export const ARNS_ROOT_HOST = env.varOrUndefined('ARNS_ROOT_HOST');
export const SANDBOX_PROTOCOL = env.varOrUndefined('SANDBOX_PROTOCOL');
export const START_WRITERS =
env.varOrDefault('START_WRITERS', 'true') === 'true';
24 changes: 16 additions & 8 deletions src/data/read-through-data-cache.ts
Original file line number Diff line number Diff line change
Expand Up @@ -158,14 +158,22 @@ export class ReadThroughDataCache implements ContiguousDataSource {
const hash = hasher.digest('base64url');

this.log.info('Successfully cached data', { id, hash });
await this.contiguousDataIndex.saveDataContentAttributes({
id,
dataRoot: attributes?.dataRoot,
hash,
dataSize: data.size,
contentType: data.sourceContentType,
cachedAt: currentUnixTimestamp(),
});
try {
await this.contiguousDataIndex.saveDataContentAttributes({
id,
dataRoot: attributes?.dataRoot,
hash,
dataSize: data.size,
contentType: data.sourceContentType,
cachedAt: currentUnixTimestamp(),
});
} catch (error: any) {
this.log.error('Error saving data content attributes:', {
id,
message: error.message,
stack: error.stack,
});
}

try {
await this.dataStore.finalize(cacheStream, hash);
Expand Down

0 comments on commit 44add3e

Please sign in to comment.