Clean up diff
This commit is contained in:
parent
8d695999c6
commit
10568efebe
6 changed files with 25 additions and 57 deletions
|
|
@ -23,7 +23,6 @@ pub type Transaction<'a> = sqlx::Transaction<'a, Sqlite>;
|
||||||
|
|
||||||
impl Database {
|
impl Database {
|
||||||
pub async fn try_new(config: &DatabaseConfig) -> Result<Self> {
|
pub async fn try_new(config: &DatabaseConfig) -> Result<Self> {
|
||||||
// Create the databases directory if it doesn't exist
|
|
||||||
tokio::fs::create_dir_all(&config.databases_directory_path)
|
tokio::fs::create_dir_all(&config.databases_directory_path)
|
||||||
.await
|
.await
|
||||||
.with_context(|| {
|
.with_context(|| {
|
||||||
|
|
@ -67,7 +66,6 @@ impl Database {
|
||||||
.databases_directory_path
|
.databases_directory_path
|
||||||
.join(format!("{vault}.sqlite"));
|
.join(format!("{vault}.sqlite"));
|
||||||
|
|
||||||
// Continue with database connection setup
|
|
||||||
let connection_options = SqliteConnectOptions::new()
|
let connection_options = SqliteConnectOptions::new()
|
||||||
.filename(file_name.clone())
|
.filename(file_name.clone())
|
||||||
.create_if_missing(true)
|
.create_if_missing(true)
|
||||||
|
|
|
||||||
|
|
@ -107,7 +107,7 @@ export class FileOperations {
|
||||||
currentText = currentText.replace(/\r\n/g, "\n");
|
currentText = currentText.replace(/\r\n/g, "\n");
|
||||||
if (currentText !== expectedText) {
|
if (currentText !== expectedText) {
|
||||||
this.logger.debug(
|
this.logger.debug(
|
||||||
`Performing a 3-way merge for ${path} with the expected content:\n${expectedText}`
|
`Performing a 3-way merge for ${path} with the expected content`
|
||||||
);
|
);
|
||||||
|
|
||||||
return mergeText(expectedText, currentText, newText);
|
return mergeText(expectedText, currentText, newText);
|
||||||
|
|
|
||||||
|
|
@ -452,7 +452,10 @@ export interface components {
|
||||||
Array_of_uint8: number[];
|
Array_of_uint8: number[];
|
||||||
CreateDocumentVersion: {
|
CreateDocumentVersion: {
|
||||||
contentBase64: string;
|
contentBase64: string;
|
||||||
/** Format: uuid */
|
/**
|
||||||
|
* Format: uuid
|
||||||
|
* @description The client can decide the document id (if it wishes to) in order to help with syncing. If the client does not provide a document id, the server will generate one. If the client provides a document id it must not already exist in the database.
|
||||||
|
*/
|
||||||
documentId?: string | null;
|
documentId?: string | null;
|
||||||
relativePath: string;
|
relativePath: string;
|
||||||
};
|
};
|
||||||
|
|
@ -476,7 +479,6 @@ export interface components {
|
||||||
type: "FastForwardUpdate";
|
type: "FastForwardUpdate";
|
||||||
/** Format: date-time */
|
/** Format: date-time */
|
||||||
updatedDate: string;
|
updatedDate: string;
|
||||||
vaultId: string;
|
|
||||||
/** Format: int64 */
|
/** Format: int64 */
|
||||||
vaultUpdateId: number;
|
vaultUpdateId: number;
|
||||||
}
|
}
|
||||||
|
|
@ -490,7 +492,6 @@ export interface components {
|
||||||
type: "MergingUpdate";
|
type: "MergingUpdate";
|
||||||
/** Format: date-time */
|
/** Format: date-time */
|
||||||
updatedDate: string;
|
updatedDate: string;
|
||||||
vaultId: string;
|
|
||||||
/** Format: int64 */
|
/** Format: int64 */
|
||||||
vaultUpdateId: number;
|
vaultUpdateId: number;
|
||||||
};
|
};
|
||||||
|
|
@ -502,7 +503,6 @@ export interface components {
|
||||||
relativePath: string;
|
relativePath: string;
|
||||||
/** Format: date-time */
|
/** Format: date-time */
|
||||||
updatedDate: string;
|
updatedDate: string;
|
||||||
vaultId: string;
|
|
||||||
/** Format: int64 */
|
/** Format: int64 */
|
||||||
vaultUpdateId: number;
|
vaultUpdateId: number;
|
||||||
};
|
};
|
||||||
|
|
@ -513,7 +513,6 @@ export interface components {
|
||||||
relativePath: string;
|
relativePath: string;
|
||||||
/** Format: date-time */
|
/** Format: date-time */
|
||||||
updatedDate: string;
|
updatedDate: string;
|
||||||
vaultId: string;
|
|
||||||
/** Format: int64 */
|
/** Format: int64 */
|
||||||
vaultUpdateId: number;
|
vaultUpdateId: number;
|
||||||
};
|
};
|
||||||
|
|
|
||||||
|
|
@ -60,24 +60,6 @@ export class Syncer {
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
private static async forgivingFileNotFoundWrapper<T>(
|
|
||||||
fn: () => Promise<T>,
|
|
||||||
logger: Logger
|
|
||||||
): Promise<T | undefined> {
|
|
||||||
try {
|
|
||||||
return await fn();
|
|
||||||
} catch (e) {
|
|
||||||
if (e instanceof FileNotFoundError) {
|
|
||||||
logger.debug(
|
|
||||||
`File has been deleted or moved before we had a chance to inspect it, skipping`
|
|
||||||
);
|
|
||||||
return undefined;
|
|
||||||
}
|
|
||||||
|
|
||||||
throw e;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public addRemainingOperationsListener(
|
public addRemainingOperationsListener(
|
||||||
listener: (remainingOperations: number) => void
|
listener: (remainingOperations: number) => void
|
||||||
): void {
|
): void {
|
||||||
|
|
@ -355,13 +337,7 @@ export class Syncer {
|
||||||
// Perhaps the file has been moved; let's check by looking at the deleted files
|
// Perhaps the file has been moved; let's check by looking at the deleted files
|
||||||
const contentHash = await this.syncQueue.add(async () => {
|
const contentHash = await this.syncQueue.add(async () => {
|
||||||
const contentBytes =
|
const contentBytes =
|
||||||
await Syncer.forgivingFileNotFoundWrapper(
|
await this.operations.read(relativePath); // this can throw FileNotFoundError
|
||||||
async () => this.operations.read(relativePath),
|
|
||||||
this.logger
|
|
||||||
);
|
|
||||||
if (contentBytes === undefined) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
return hash(contentBytes);
|
return hash(contentBytes);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -251,10 +251,7 @@ export class MockAgent extends MockClient {
|
||||||
`Decided to create file ${file} with content ${content}`
|
`Decided to create file ${file} with content ${content}`
|
||||||
);
|
);
|
||||||
|
|
||||||
return this.create(
|
return this.create(file, new TextEncoder().encode(` ${content} `));
|
||||||
file,
|
|
||||||
new TextEncoder().encode(` |${content}| `)
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private async changeFetchChangesUpdateIntervalMsAction(): Promise<void> {
|
private async changeFetchChangesUpdateIntervalMsAction(): Promise<void> {
|
||||||
|
|
@ -328,7 +325,7 @@ export class MockAgent extends MockClient {
|
||||||
`Decided to update file ${file} with ${content}`
|
`Decided to update file ${file} with ${content}`
|
||||||
);
|
);
|
||||||
this.doNotTouchWhileOffline.push(file);
|
this.doNotTouchWhileOffline.push(file);
|
||||||
await this.atomicUpdateText(file, (old) => old + ` |${content}| `);
|
await this.atomicUpdateText(file, (old) => old + ` ${content} `);
|
||||||
}
|
}
|
||||||
|
|
||||||
private async deleteFileAction(files: RelativePath[]): Promise<void> {
|
private async deleteFileAction(files: RelativePath[]): Promise<void> {
|
||||||
|
|
|
||||||
|
|
@ -46,10 +46,6 @@ async function runTest({
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
// for debugging
|
|
||||||
// eslint-disable-next-line
|
|
||||||
(globalThis as any).clients = clients;
|
|
||||||
|
|
||||||
try {
|
try {
|
||||||
await Promise.all(clients.map(async (client) => client.init()));
|
await Promise.all(clients.map(async (client) => client.init()));
|
||||||
|
|
||||||
|
|
@ -109,20 +105,22 @@ async function runTest({
|
||||||
}
|
}
|
||||||
|
|
||||||
async function runTests(): Promise<void> {
|
async function runTests(): Promise<void> {
|
||||||
for (const concurrency of [
|
for (const useSlowFileEvents of [false, true]) {
|
||||||
16,
|
for (const concurrency of [
|
||||||
1 // test with concurrency 1 to check for deadlocks
|
16,
|
||||||
]) {
|
1 // test with concurrency 1 to check for deadlocks
|
||||||
for (const doDeletes of [true, false]) {
|
]) {
|
||||||
for (const useSlowFileEvents of [true, false]) {
|
for (const doDeletes of [true, false]) {
|
||||||
await runTest({
|
for (let i = 0; i < 4; i++) {
|
||||||
agentCount: 4,
|
await runTest({
|
||||||
concurrency,
|
agentCount: 2,
|
||||||
iterations: 200,
|
concurrency,
|
||||||
doDeletes,
|
iterations: 200,
|
||||||
useSlowFileEvents,
|
doDeletes,
|
||||||
jitterScaleInSeconds: 0.75
|
useSlowFileEvents,
|
||||||
});
|
jitterScaleInSeconds: 0.75
|
||||||
|
});
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -148,7 +146,7 @@ runTests()
|
||||||
.then(() => {
|
.then(() => {
|
||||||
process.exit(0);
|
process.exit(0);
|
||||||
})
|
})
|
||||||
.catch(async (err: unknown) => {
|
.catch((err: unknown) => {
|
||||||
console.error(err);
|
console.error(err);
|
||||||
process.exit(1);
|
process.exit(1);
|
||||||
});
|
});
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue