Skip to content

Commit

Permalink
Fixes Issue #610
Browse files Browse the repository at this point in the history
  • Loading branch information
zachlankton authored and ejscribner committed Jan 27, 2022
1 parent a5a52f3 commit d09e492
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 20 deletions.
16 changes: 10 additions & 6 deletions src/model/index/n1ql/ensure-n1ql-indexes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -92,13 +92,17 @@ export const ensureN1qlIndexes = async (ottoman: Ottoman, n1qlIndexes) => {
}
}

let names: string[] = [];
for (const key in indexesToBuild) {
names = [...names, ...(indexesToBuild[key] || [])];
}

ottoman.indexOnlinePromise = ottoman.queryIndexManager.watchIndexes(bucketName, names, 600000, {
watchPrimary: false,
});

if (ottoman.indexReadyHooks && ottoman.indexReadyHooks.length > 0) {
let names: string[] = [];
for (const key in indexesToBuild) {
names = [...names, ...(indexesToBuild[key] || [])];
}
ottoman.indexOnlinePromise = ottoman.queryIndexManager
.watchIndexes(bucketName, names, 600000, { watchPrimary: false })
ottoman.indexOnlinePromise
.then(() => {
ottoman.indexOnline = true;
ottoman.indexReadyHooks.forEach((fn) => fn(null, ottoman));
Expand Down
25 changes: 11 additions & 14 deletions src/ottoman/ottoman.ts
Original file line number Diff line number Diff line change
Expand Up @@ -507,21 +507,18 @@ const tryCreateCollection = async (
retries = 3,
delayMS = 5000,
) => {
try {
await createCollection({ collectionManager, collectionName, scopeName, maxExpiry });
return;
} catch (e) {
if (!(e instanceof (couchbase as any).CollectionExistsError)) {
if (retries > 0) {
await delay(delayMS);
await tryCreateCollection(
{ collectionManager, collectionName, scopeName, maxExpiry },
retries - 1,
delayMS + 5000,
);
return;
}
let collectionDoesNotExists = true;
let testDelay = 0;
let testCount = 1;
while (collectionDoesNotExists && testCount < retries + 1) {
await delay(testDelay);
try {
await createCollection({ collectionManager, collectionName, scopeName, maxExpiry });
} catch (e) {
if (e instanceof (couchbase as any).CollectionExistsError) collectionDoesNotExists = false;
}
testDelay += Math.max(Math.min(testDelay * 10, delayMS), 100);
testCount++;
}
};

Expand Down

0 comments on commit d09e492

Please sign in to comment.