From f82b407f305c149bc7a53457a5f77916c8db759a Mon Sep 17 00:00:00 2001 From: Andrew Kingston Date: Mon, 25 Jul 2022 12:17:40 +0100 Subject: [PATCH 1/3] Ignore 409s in write-through cache --- packages/backend-core/src/cache/writethrough.ts | 7 +++---- packages/backend-core/src/logging.ts | 5 +++++ 2 files changed, 8 insertions(+), 4 deletions(-) diff --git a/packages/backend-core/src/cache/writethrough.ts b/packages/backend-core/src/cache/writethrough.ts index e11ca0acaa..701351d75b 100644 --- a/packages/backend-core/src/cache/writethrough.ts +++ b/packages/backend-core/src/cache/writethrough.ts @@ -1,5 +1,6 @@ import BaseCache from "./base" import { getWritethroughClient } from "../redis/init" +import { logInfo } from "../logging" const DEFAULT_WRITE_RATE_MS = 10000 let CACHE: BaseCache | null = null @@ -51,10 +52,8 @@ export async function put( if (err.status !== 409) { throw err } else { - // get the rev, update over it - this is risky, may change in future - const readDoc = await db.get(doc._id) - doc._rev = readDoc._rev - await writeDb(doc) + // Swallow 409s but log them + logInfo(`Ignoring conflict in write-through cache`) } } } diff --git a/packages/backend-core/src/logging.ts b/packages/backend-core/src/logging.ts index 68c3307b2f..fcfa04bbb9 100644 --- a/packages/backend-core/src/logging.ts +++ b/packages/backend-core/src/logging.ts @@ -15,6 +15,11 @@ export function logAlert(message: string, e?: any) { console.error(`bb-alert: ${message} ${errorJson}`) } +export function logInfo(message: string) { + console.warn(`bb-info: ${message}`) +} + export default { logAlert, + logInfo, } From 8bd254f31316f094777b6594827511f9813f449a Mon Sep 17 00:00:00 2001 From: Andrew Kingston Date: Mon, 25 Jul 2022 12:22:27 +0100 Subject: [PATCH 2/3] Use log rather than warn for logInfo --- packages/backend-core/src/logging.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/backend-core/src/logging.ts b/packages/backend-core/src/logging.ts index fcfa04bbb9..63bdc092e9 100644 --- a/packages/backend-core/src/logging.ts +++ b/packages/backend-core/src/logging.ts @@ -16,7 +16,7 @@ export function logAlert(message: string, e?: any) { } export function logInfo(message: string) { - console.warn(`bb-info: ${message}`) + console.log(`bb-info: ${message}`) } export default { From d9dacbc901c149daaea68f551d46a1d1b4a3bbde Mon Sep 17 00:00:00 2001 From: Andrew Kingston Date: Mon, 25 Jul 2022 12:23:30 +0100 Subject: [PATCH 3/3] Use warn rather than info when notifying about ignored conflicts --- packages/backend-core/src/cache/writethrough.ts | 4 ++-- packages/backend-core/src/logging.ts | 6 +++--- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/packages/backend-core/src/cache/writethrough.ts b/packages/backend-core/src/cache/writethrough.ts index 701351d75b..ec6b1604c8 100644 --- a/packages/backend-core/src/cache/writethrough.ts +++ b/packages/backend-core/src/cache/writethrough.ts @@ -1,6 +1,6 @@ import BaseCache from "./base" import { getWritethroughClient } from "../redis/init" -import { logInfo } from "../logging" +import { logWarn } from "../logging" const DEFAULT_WRITE_RATE_MS = 10000 let CACHE: BaseCache | null = null @@ -53,7 +53,7 @@ export async function put( throw err } else { // Swallow 409s but log them - logInfo(`Ignoring conflict in write-through cache`) + logWarn(`Ignoring conflict in write-through cache`) } } } diff --git a/packages/backend-core/src/logging.ts b/packages/backend-core/src/logging.ts index 63bdc092e9..8eda15ac79 100644 --- a/packages/backend-core/src/logging.ts +++ b/packages/backend-core/src/logging.ts @@ -15,11 +15,11 @@ export function logAlert(message: string, e?: any) { console.error(`bb-alert: ${message} ${errorJson}`) } -export function logInfo(message: string) { - console.log(`bb-info: ${message}`) +export function logWarn(message: string) { + console.warn(`bb-warn: ${message}`) } export default { logAlert, - logInfo, + logWarn, }