Skip to content

Commit

Permalink
wip part 2
Browse files Browse the repository at this point in the history
  • Loading branch information
m5r committed Dec 19, 2024
1 parent 6ab3758 commit 23d20e8
Show file tree
Hide file tree
Showing 5 changed files with 53 additions and 18 deletions.
3 changes: 1 addition & 2 deletions api/src/services/setup/check-install.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,14 +9,13 @@ const startupLog = require('./startup-log');
const checkInstallForDb = async (database) => {
const check = {};
const allDdocs = await ddocsService.getDdocs(database);
// console.log("allDdocs", allDdocs);
const bundledDdocs = await upgradeUtils.getBundledDdocs(database);
console.log("bundledDdocs", bundledDdocs);

const liveDdocs = allDdocs.filter(ddoc => !ddocsService.isStaged(ddoc._id));
const stagedDdocs = allDdocs.filter(ddoc => ddocsService.isStaged(ddoc._id));

const liveDdocsCheck = ddocsService.compareDdocs(bundledDdocs, liveDdocs);
console.log("liveDdocsCheck.different", liveDdocsCheck.different);
check.missing = liveDdocsCheck.missing;
check.different = liveDdocsCheck.different;

Expand Down
2 changes: 1 addition & 1 deletion api/src/services/setup/upgrade-steps.js
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ const indexStagedViews = async () => {
const viewsToIndex = await viewIndexer.getViewsToIndex();
const viewIndexingPromise = viewIndexer.indexViews(viewsToIndex);
const stopQueryingIndexers = viewIndexerProgress.log();
const nouveauIndexingPromise = Promise.resolve(); // TODO
const nouveauIndexingPromise = Promise.resolve();
await Promise.all([viewIndexingPromise, nouveauIndexingPromise]);
stopQueryingIndexers();
};
Expand Down
15 changes: 6 additions & 9 deletions api/src/services/setup/view-indexer-progress.js
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ const updateRunningTasks = (indexers, activeTasks = []) => {
indexers.push(indexer);
}

console.log(`${task.node}-${task.pid} progress`, task.progress);
indexer.tasks[`${task.node}-${task.pid}`] = task.progress;
});
};
Expand Down Expand Up @@ -90,17 +91,13 @@ const getIndexers = async (indexers = []) => {
try {
const activeTasks = await db.activeTasks();
const tasks = activeTasks.filter(task => {
const isViewIndexingTask = task.type === 'indexer';
if (isViewIndexingTask) {
return DDOC_PREFIX.test(String(task.design_document));
const isFirstNouveauIndexingTask = task.type === 'search_indexer' &&
task.design_document === '_design/medic-nouveau';
if (isFirstNouveauIndexingTask) {
return true;
}

const isNouveauIndexingTask = task.type === 'search_indexer';
if (isNouveauIndexingTask) {
return task.design_document === '_design/medic-nouveau';
}

return false;
return DDOC_PREFIX.test(String(task.design_document));
});
// We assume all previous tasks have finished.
console.log("indexers 1", indexers);
Expand Down
50 changes: 44 additions & 6 deletions api/src/services/setup/view-indexer.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,17 @@ let continueIndexing;
const indexViews = async (viewsToIndex) => {
continueIndexing = true;

console.log("viewsToIndex", viewsToIndex);
if (!Array.isArray(viewsToIndex)) {
console.log("not array");
await upgradeLogService.setIndexed();
return;
}

await upgradeLogService.setIndexing();
const indexResult = await Promise.all(viewsToIndex.map(indexView => indexView()));
console.log("indexResult", indexResult);
console.log("continueIndexing", continueIndexing);
if (continueIndexing) {
await upgradeLogService.setIndexed();
}
Expand All @@ -38,14 +42,19 @@ const getViewsToIndex = async () => {
for (const database of DATABASES) {
const stagedDdocs = await ddocsService.getStagedDdocs(database);
stagedDdocs.forEach(ddoc => {
if (!ddoc.views || !_.isObject(ddoc.views)) {
return;
if (ddoc.views && !_.isObject(ddoc.views)) {
const ddocViewIndexPromises = Object
.keys(ddoc.views)
.map(viewName => indexView.bind({}, database.name, ddoc._id, viewName));
viewsToIndex.push(...ddocViewIndexPromises);
}

const ddocViewIndexPromises = Object
.keys(ddoc.views)
.map(viewName => indexView.bind({}, database.name, ddoc._id, viewName));
viewsToIndex.push(...ddocViewIndexPromises);
if (ddoc.nouveau && !_.isObject(ddoc.nouveau)) {
const ddocNouveauIndexPromises = Object
.keys(ddoc.nouveau)
.map(indexName => indexNouveauIndex.bind({}, database.name, ddoc._id, indexName));
viewsToIndex.push(...ddocNouveauIndexPromises);
}
});
}
return viewsToIndex;
Expand Down Expand Up @@ -79,7 +88,36 @@ const indexView = async (dbName, ddocId, viewName) => {
} while (continueIndexing);
};

/**
* Returns a promise that resolves when a nouveau index is indexed.
* Retries querying the index until no error is thrown
* @param {String} dbName
* @param {String} ddocId
* @param {String} indexName
* @return {Promise}
*/
const indexNouveauIndex = async (dbName, ddocId, indexName) => {
do {
try {
return await request.get({
uri: `${environment.serverUrl}/${dbName}/_design/${ddocId}/_nouveau/${indexName}`,
json: true,
qs: { q: '*:*', limit: 1 },
});
} catch (requestError) {
if (!continueIndexing) {
return;
}

if (!requestError || !requestError.error || !SOCKET_TIMEOUT_ERROR_CODE.includes(requestError.error.code)) {
throw requestError;
}
}
} while (continueIndexing);
};

const stopIndexing = () => {
console.trace("************ stopIndexing");
continueIndexing = false;
};

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
function (doc) {
'different 2';
var skip = ['_id', '_rev', 'type', 'refid', 'geolocation'];
var toIndex = '';

Expand Down

0 comments on commit 23d20e8

Please sign in to comment.