Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
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
22,388 changes: 11,217 additions & 11,171 deletions dist/browser.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion dist/browser.min.js

Large diffs are not rendered by default.

17 changes: 17 additions & 0 deletions src/node-cache.ts
Original file line number Diff line number Diff line change
Expand Up @@ -187,6 +187,23 @@ export class NodeCache {
this._cache.clear();
}

/**
* Invalidates all cache entries whose recorded address matches any address in `addresses`.
* Call this before freeing (deallocating) records so stale cache pointers never cause
* a CorruptRecordError when the freed records are later reused by a different node.
*/
invalidateAddress(addresses: Array<{ pageNr: number; recordNr: number }>) {
for (const [path, entry] of this._cache) {
const addr = entry.nodeInfo.address as { pageNr?: number; recordNr?: number } | undefined;
if (!addr || typeof addr.pageNr !== 'number') { return; }
const stale = addresses.some(a => a.pageNr === addr.pageNr && a.recordNr === addr.recordNr);
if (stale) {
console.error(`CACHE INVALIDATED for path ${path} because it used freed address ${addr.pageNr},${addr.recordNr}`);
this._cache.delete(path);
}
}
}

/**
* Finds cached NodeInfo for a given path. Returns null if the info is not found in cache
* @returns returns cached info, a promise, or null
Expand Down
3 changes: 3 additions & 0 deletions src/storage/binary/binary-storage-address-range.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
export class StorageAddressRange {
constructor(public pageNr: number, public recordNr: number, public length: number) { }
}
74 changes: 74 additions & 0 deletions src/storage/binary/binary-storage-settings.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
import { StorageSettings } from '../storage-settings.js';

export class AceBaseStorageSettings extends StorageSettings {
/**
* record size in bytes, defaults to 128 (recommended). Max is 65536
* @default 128
*/
recordSize = 128;

/**
* page size in records, defaults to 1024 (recommended). Max is 65536
* @default 1024
*/
pageSize = 1024;

/**
* type of database content. Determines the name of the file within the .acebase directory
*/
type: 'data' | 'transaction' | 'auth' = 'data';

/**
* settings to use for transaction logging
*/
transactions: AceBaseTransactionLogSettings;

/**
* Use future FST version (not implemented yet)
*/
fst2 = false;

constructor(settings: Partial<AceBaseStorageSettings> = {}) {
super(settings);
if (typeof settings.recordSize === 'number') { this.recordSize = settings.recordSize; }
if (typeof settings.pageSize === 'number') { this.pageSize = settings.pageSize; }
if (typeof settings.type === 'string') { this.type = settings.type; }
this.transactions = new AceBaseTransactionLogSettings(settings.transactions);
}
}

class AceBaseTransactionLogSettings {

/**
* Whether transaction logging is enabled.
* @default false
*/
log = false;

/**
* Max age of transactions to keep in logfile. Set to 0 to disable cleaning up and keep all transactions
* @default 30
*/
maxAge = 30;

/**
* Whether write operations wait for the transaction to be logged before resolving their promises.
*/
noWait = false;

/**
* BETA functionality - logs mutations made to a separate database file so they can be retrieved later
* for database syncing / replication. Implementing this into acebase itself will allow the current
* sync implementation in acebase-client to become better: it can simply request a mutations stream from
* the server after disconnects by passing a cursor or timestamp, instead of downloading whole nodes before
* applying local changes. This will also enable horizontal scaling: replication with remote db instances
* becomes possible.
*
* Still under development, disabled by default. See transaction-logs.spec for tests
*/
constructor(settings: Partial<AceBaseTransactionLogSettings> = {}) {
if (typeof settings.log === 'boolean') { this.log = settings.log; }
if (typeof settings.maxAge === 'number') { this.maxAge = settings.maxAge; }
if (typeof settings.noWait === 'boolean') { this.noWait = settings.noWait; }
}
}
Loading