Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
39 changes: 38 additions & 1 deletion bin/harper.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,42 @@ const HDB_LEADER_URL = values['leader-url'] || process.env.HDB_LEADER_URL || val
// Check to see if extra args are passed to harper, this could be the case with api-ops through the CLI
const hasPositionalArg = Boolean(process.argv[2] && !process.argv[2].startsWith('-'));

async function completeCloneAvailabilityFinalization() {
Comment thread
kriszyp marked this conversation as resolved.
const { existsSync } = require('node:fs');
const { join } = require('node:path');
const { getHdbBasePath } = require('../core/utility/environment/environmentManager.js');
const rootPath = getHdbBasePath();
if (typeof rootPath !== 'string') return;
const finalizationPath = join(rootPath, '.cloneAvailabilityFinalization');
if (!existsSync(finalizationPath)) return;
try {
const { set: setStatus } = require('../core/server/status/index.js');
await setStatus({ id: 'availability', status: 'Available' });
unlinkIfPresent(join(rootPath, '.cloneSyncBaseline.json'));
if (
unlinkIfPresent(join(rootPath, '.cloneSyncInProgress')) &&
unlinkIfPresent(join(rootPath, '.cloneAttempt.json'))
) {
delete process.env.HARPER_CLONE_ATTEMPT;
unlinkIfPresent(finalizationPath);
}
} catch (error) {
console.error(`Failed to complete clone availability finalization: ${error}`);
}
}

function unlinkIfPresent(path) {
const { unlinkSync } = require('node:fs');
try {
unlinkSync(path);
return true;
} catch (error) {
if (error?.code === 'ENOENT') return true;
console.error(`Failed to remove clone finalization marker ${path}: ${error}`);
return false;
}
}

if (HDB_LEADER_URL && !hasPositionalArg) {
// If rootpath is provided ensure that an uppercase version of the arg is also added to process.argv so it can be picked
// by anything expecting it in uppercase.
Expand All @@ -44,7 +80,8 @@ if (HDB_LEADER_URL && !hasPositionalArg) {
// Clone Node will start Harper after cloning is complete. If this node is already marked as cloned,
// it will skip the cloning process and just start Harper.
cloneNode()
.then((message) => {
.then(async (message) => {
await completeCloneAvailabilityFinalization();
if (message) {
console.log(message);
}
Expand Down
Loading