Skip to content

Commit 172ac2e

Browse files
committed
Some cleanup of debug logging.
1 parent 5a4d2a6 commit 172ac2e

File tree

2 files changed

+23
-23
lines changed

2 files changed

+23
-23
lines changed

packages/common/src/client/sync/bucket/SqliteBucketStorage.ts

Lines changed: 16 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -94,11 +94,11 @@ export class SqliteBucketStorage extends BaseObserver<BucketStorageListener> imp
9494
async saveSyncData(batch: SyncDataBatch, fixedKeyFormat: boolean = false) {
9595
await this.writeTransaction(async (tx) => {
9696
for (const b of batch.buckets) {
97-
const result = await tx.execute('INSERT INTO powersync_operations(op, data) VALUES(?, ?)', [
97+
await tx.execute('INSERT INTO powersync_operations(op, data) VALUES(?, ?)', [
9898
'save',
9999
JSON.stringify({ buckets: [b.toJSON(fixedKeyFormat)] })
100100
]);
101-
this.logger.debug('saveSyncData', JSON.stringify(result));
101+
this.logger.debug(`Saved batch of data for bucket: ${b.bucket}, operations: ${b.data.length}`);
102102
}
103103
});
104104
}
@@ -117,7 +117,7 @@ export class SqliteBucketStorage extends BaseObserver<BucketStorageListener> imp
117117
await tx.execute('INSERT INTO powersync_operations(op, data) VALUES(?, ?)', ['delete_bucket', bucket]);
118118
});
119119

120-
this.logger.debug('done deleting bucket');
120+
this.logger.debug(`Done deleting bucket ${bucket}`);
121121
}
122122

123123
async hasCompletedSync() {
@@ -141,6 +141,11 @@ export class SqliteBucketStorage extends BaseObserver<BucketStorageListener> imp
141141
}
142142
return { ready: false, checkpointValid: false, checkpointFailures: r.checkpointFailures };
143143
}
144+
if (priority == null) {
145+
this.logger.debug(`Validated checksums checkpoint ${checkpoint.last_op_id}`);
146+
} else {
147+
this.logger.debug(`Validated checksums for partial checkpoint ${checkpoint.last_op_id}, priority ${priority}`);
148+
}
144149

145150
let buckets = checkpoint.buckets;
146151
if (priority !== undefined) {
@@ -160,7 +165,6 @@ export class SqliteBucketStorage extends BaseObserver<BucketStorageListener> imp
160165

161166
const valid = await this.updateObjectsFromBuckets(checkpoint, priority);
162167
if (!valid) {
163-
this.logger.debug('Not at a consistent checkpoint - cannot update local db');
164168
return { ready: false, checkpointValid: true };
165169
}
166170

@@ -223,7 +227,6 @@ export class SqliteBucketStorage extends BaseObserver<BucketStorageListener> imp
223227
]);
224228

225229
const resultItem = rs.rows?.item(0);
226-
this.logger.debug('validateChecksums priority, checkpoint, result item', priority, checkpoint, resultItem);
227230
if (!resultItem) {
228231
return {
229232
checkpointValid: false,
@@ -264,34 +267,32 @@ export class SqliteBucketStorage extends BaseObserver<BucketStorageListener> imp
264267

265268
const opId = await cb();
266269

267-
this.logger.debug(`[updateLocalTarget] Updating target to checkpoint ${opId}`);
268-
269270
return this.writeTransaction(async (tx) => {
270271
const anyData = await tx.execute('SELECT 1 FROM ps_crud LIMIT 1');
271272
if (anyData.rows?.length) {
272273
// if isNotEmpty
273-
this.logger.debug('updateLocalTarget', 'ps crud is not empty');
274+
this.logger.debug(`New data uploaded since write checkpoint ${opId} - need new write checkpoint`);
274275
return false;
275276
}
276277

277278
const rs = await tx.execute("SELECT seq FROM sqlite_sequence WHERE name = 'ps_crud'");
278279
if (!rs.rows?.length) {
279280
// assert isNotEmpty
280-
throw new Error('SQlite Sequence should not be empty');
281+
throw new Error('SQLite Sequence should not be empty');
281282
}
282283

283284
const seqAfter: number = rs.rows?.item(0)['seq'];
284-
this.logger.debug('seqAfter', JSON.stringify(rs.rows?.item(0)));
285285
if (seqAfter != seqBefore) {
286-
this.logger.debug('seqAfter != seqBefore', seqAfter, seqBefore);
286+
this.logger.debug(
287+
`New data uploaded since write checpoint ${opId} - need new write checkpoint (sequence updated)`
288+
);
289+
287290
// New crud data may have been uploaded since we got the checkpoint. Abort.
288291
return false;
289292
}
290293

291-
const response = await tx.execute("UPDATE ps_buckets SET target_op = CAST(? as INTEGER) WHERE name='$local'", [
292-
opId
293-
]);
294-
this.logger.debug(['[updateLocalTarget] Response from updating target_op ', JSON.stringify(response)]);
294+
this.logger.debug(`Updating target write checkpoint to ${opId}`);
295+
await tx.execute("UPDATE ps_buckets SET target_op = CAST(? as INTEGER) WHERE name='$local'", [opId]);
295296
return true;
296297
});
297298
}

packages/common/src/client/sync/stream/AbstractStreamingSyncImplementation.ts

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -327,11 +327,10 @@ export abstract class AbstractStreamingSyncImplementation
327327

328328
async getWriteCheckpoint(): Promise<string> {
329329
const clientId = await this.options.adapter.getClientId();
330-
this.logger.debug(`Creating write checkpoint for ${clientId}`);
331330
let path = `/write-checkpoint2.json?client_id=${clientId}`;
332331
const response = await this.options.remote.get(path);
333332
const checkpoint = response['data']['write_checkpoint'] as string;
334-
this.logger.debug(`Got write checkpoint: ${checkpoint}`);
333+
this.logger.debug(`Created write checkpoint: ${checkpoint}`);
335334
return checkpoint;
336335
}
337336

@@ -374,10 +373,10 @@ The next upload iteration will be delayed.`);
374373
});
375374
} else {
376375
// Uploading is completed
377-
this.logger.debug('Upload complete, creating write checkpoint');
378376
const neededUpdate = await this.options.adapter.updateLocalTarget(() => this.getWriteCheckpoint());
379-
if (neededUpdate == false) {
380-
this.logger.debug('No write checkpoint needed');
377+
if (neededUpdate == false && checkedCrudItem != null) {
378+
// Only log this if there was something to upload
379+
this.logger.debug('Upload complete, no write checkpoint needed.');
381380
}
382381
break;
383382
}
@@ -1090,20 +1089,20 @@ The next upload iteration will be delayed.`);
10901089
let result = await this.options.adapter.syncLocalDatabase(checkpoint);
10911090

10921091
if (!result.checkpointValid) {
1093-
this.logger.debug('Checksum mismatch in checkpoint, will reconnect');
1092+
this.logger.debug(`Checksum mismatch in checkpoint ${checkpoint.last_op_id}, will reconnect`);
10941093
// This means checksums failed. Start again with a new checkpoint.
10951094
// TODO: better back-off
10961095
await new Promise((resolve) => setTimeout(resolve, 50));
10971096
return { applied: false, endIteration: true };
10981097
} else if (!result.ready) {
10991098
this.logger.debug(
1100-
'Could not apply checkpoint due to local data. We will retry applying the checkpoint after that upload is completed.'
1099+
`Could not apply checkpoint ${checkpoint.last_op_id} due to local data. We will retry applying the checkpoint after that upload is completed.`
11011100
);
11021101

11031102
return { applied: false, endIteration: false };
11041103
}
11051104

1106-
this.logger.debug('validated checkpoint', checkpoint);
1105+
this.logger.debug(`Applied checkpoint ${checkpoint.last_op_id}`, checkpoint);
11071106
this.updateSyncStatus({
11081107
connected: true,
11091108
lastSyncedAt: new Date(),

0 commit comments

Comments
 (0)