Skip to content
Merged
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
5 changes: 5 additions & 0 deletions .changeset/healthy-carrots-exercise.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@powersync/common': patch
---

Remove unused compaction logic.
10 changes: 0 additions & 10 deletions packages/common/src/client/sync/bucket/BucketStorageAdapter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -96,16 +96,6 @@ export interface BucketStorageAdapter extends BaseObserver<BucketStorageListener

hasCompletedSync(): Promise<boolean>;
updateLocalTarget(cb: () => Promise<string>): Promise<boolean>;
/**
* Exposed for tests only.
*/
autoCompact(): Promise<void>;

/**
* Exposed for tests only.
*/
forceCompact(): Promise<void>;

getMaxOpId(): string;

/**
Expand Down
51 changes: 0 additions & 51 deletions packages/common/src/client/sync/bucket/SqliteBucketStorage.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,28 +18,19 @@ import { CrudBatch } from './CrudBatch.js';
import { CrudEntry, CrudEntryJSON } from './CrudEntry.js';
import { SyncDataBatch } from './SyncDataBatch.js';

const COMPACT_OPERATION_INTERVAL = 1_000;

export class SqliteBucketStorage extends BaseObserver<BucketStorageListener> implements BucketStorageAdapter {
public tableNames: Set<string>;
private pendingBucketDeletes: boolean;
private _hasCompletedSync: boolean;
private updateListener: () => void;
private _clientId?: Promise<string>;

/**
* Count up, and do a compact on startup.
*/
private compactCounter = COMPACT_OPERATION_INTERVAL;

constructor(
private db: DBAdapter,
private mutex: Mutex,
private logger: ILogger = Logger.get('SqliteBucketStorage')
) {
super();
this._hasCompletedSync = false;
this.pendingBucketDeletes = true;
this.tableNames = new Set();
this.updateListener = db.registerListener({
tablesUpdated: (update) => {
Expand Down Expand Up @@ -102,16 +93,13 @@ export class SqliteBucketStorage extends BaseObserver<BucketStorageListener> imp

async saveSyncData(batch: SyncDataBatch, fixedKeyFormat: boolean = false) {
await this.writeTransaction(async (tx) => {
let count = 0;
for (const b of batch.buckets) {
const result = await tx.execute('INSERT INTO powersync_operations(op, data) VALUES(?, ?)', [
'save',
JSON.stringify({ buckets: [b.toJSON(fixedKeyFormat)] })
]);
this.logger.debug('saveSyncData', JSON.stringify(result));
count += b.data.length;
}
this.compactCounter += count;
});
}

Expand All @@ -130,7 +118,6 @@ export class SqliteBucketStorage extends BaseObserver<BucketStorageListener> imp
});

this.logger.debug('done deleting bucket');
this.pendingBucketDeletes = true;
}

async hasCompletedSync() {
Expand Down Expand Up @@ -177,8 +164,6 @@ export class SqliteBucketStorage extends BaseObserver<BucketStorageListener> imp
return { ready: false, checkpointValid: true };
}

await this.forceCompact();

return {
ready: true,
checkpointValid: true
Expand Down Expand Up @@ -260,42 +245,6 @@ export class SqliteBucketStorage extends BaseObserver<BucketStorageListener> imp
}
}

/**
* Force a compact, for tests.
*/
async forceCompact() {
this.compactCounter = COMPACT_OPERATION_INTERVAL;
this.pendingBucketDeletes = true;

await this.autoCompact();
}

async autoCompact() {
await this.deletePendingBuckets();
await this.clearRemoveOps();
}

private async deletePendingBuckets() {
if (this.pendingBucketDeletes !== false) {
await this.writeTransaction(async (tx) => {
await tx.execute('INSERT INTO powersync_operations(op, data) VALUES (?, ?)', ['delete_pending_buckets', '']);
});
// Executed once after start-up, and again when there are pending deletes.
this.pendingBucketDeletes = false;
}
}

private async clearRemoveOps() {
if (this.compactCounter < COMPACT_OPERATION_INTERVAL) {
return;
}

await this.writeTransaction(async (tx) => {
await tx.execute('INSERT INTO powersync_operations(op, data) VALUES (?, ?)', ['clear_remove_ops', '']);
});
this.compactCounter = 0;
}

async updateLocalTarget(cb: () => Promise<string>): Promise<boolean> {
const rs1 = await this.db.getAll(
"SELECT target_op FROM ps_buckets WHERE name = '$local' AND target_op = CAST(? as INTEGER)",
Expand Down
2 changes: 0 additions & 2 deletions packages/web/tests/bucket_storage.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -514,8 +514,6 @@ describe('Bucket Storage', { sequential: true }, () => {
buckets: [{ bucket: 'bucket1', checksum: 7, priority: 3 }]
});

await bucketStorage.forceCompact();

await syncLocalChecked({
last_op_id: '4',
write_checkpoint: '4',
Expand Down