Skip to content

Commit

Permalink
fix triggering replication when multiple destinations are set
Browse files Browse the repository at this point in the history
  • Loading branch information
Kerkesni committed Dec 19, 2024
1 parent 1be6653 commit 00a5b99
Showing 1 changed file with 37 additions and 39 deletions.
76 changes: 37 additions & 39 deletions crrExistingObjects.js
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,10 @@ if (!STORAGE_TYPE) {
if (!TARGET_REPLICATION_STATUS) {
TARGET_REPLICATION_STATUS = 'NEW';
}
if (!SITE_NAME) {
log.fatal('missing SITE_NAME environment variable');
process.exit(1);
}

const replicationStatusToProcess = TARGET_REPLICATION_STATUS.split(',');
replicationStatusToProcess.forEach(state => {
Expand Down Expand Up @@ -83,19 +87,16 @@ const logProgressInterval = setInterval(_logProgress, LOG_PROGRESS_INTERVAL_MS);
function _objectShouldBeUpdated(objMD) {
return replicationStatusToProcess.some(filter => {
if (filter === 'NEW') {
return (!objMD.getReplicationInfo()
|| objMD.getReplicationInfo().status === '');
return !objMD.getReplicationSiteStatus(SITE_NAME);
}
return (objMD.getReplicationInfo()
&& objMD.getReplicationInfo().status === filter);
return objMD.getReplicationSiteStatus(SITE_NAME) === filter;
});
}

function _markObjectPending(
bucket,
key,
versionId,
storageClass,
repConfig,
cb,
) {
Expand Down Expand Up @@ -159,31 +160,38 @@ function _markObjectPending(
}

// Initialize replication info, if missing
if (!objMD.getReplicationInfo()
|| !objMD.getReplicationSiteStatus(storageClass)) {
const { Rules, Role } = repConfig;
const destination = Rules[0].Destination.Bucket;
// set replication properties
const ops = objMD.getContentLength() === 0 ? ['METADATA']
: ['METADATA', 'DATA'];
const backends = [{
site: storageClass,
if (objMD.getReplicationSiteStatus(SITE_NAME) === undefined) {
let replicationInfo = objMD.getReplicationInfo();
if (!replicationInfo) {
const { Rules, Role } = repConfig;
const destination = Rules[0].Destination.Bucket;
// set replication properties
const ops = objMD.getContentLength() === 0 ? ['METADATA']
: ['METADATA', 'DATA'];
replicationInfo = {
status: 'PENDING',
content: ops,
backends: [],
destination,
storageClass: SITE_NAME,
role: Role,
storageType: STORAGE_TYPE,
};
} else {
replicationInfo.storageClass += `,${SITE_NAME}`;
if (STORAGE_TYPE) {
replicationInfo.storageType += `,${STORAGE_TYPE}`;
}
}
replicationInfo.backends.push({
site: SITE_NAME,
status: 'PENDING',
dataStoreVersionId: '',
}];
const replicationInfo = {
status: 'PENDING',
backends,
content: ops,
destination,
storageClass,
role: Role,
storageType: STORAGE_TYPE,
};
});
objMD.setReplicationInfo(replicationInfo);
}

objMD.setReplicationSiteStatus(storageClass, 'PENDING');
objMD.setReplicationSiteStatus(SITE_NAME, 'PENDING');
objMD.setReplicationStatus('PENDING');
objMD.updateMicroVersionId();
const md = objMD.getValue();
Expand Down Expand Up @@ -232,20 +240,10 @@ function _markPending(bucket, versions, cb) {
}
return next(null, res.ReplicationConfiguration);
}),
(repConfig, next) => {
const { Rules } = repConfig;
const storageClass = Rules[0].Destination.StorageClass || SITE_NAME;
if (!storageClass) {
const errMsg = 'missing SITE_NAME environment variable, must be set to'
+ ' the value of "site" property in the CRR configuration';
log.error(errMsg);
return next(new Error(errMsg));
}
return eachLimit(versions, WORKERS, (i, apply) => {
const { Key, VersionId } = i;
_markObjectPending(bucket, Key, VersionId, storageClass, repConfig, apply);
}, next);
},
(repConfig, next) => eachLimit(versions, WORKERS, (i, apply) => {
const { Key, VersionId } = i;
_markObjectPending(bucket, Key, VersionId, repConfig, apply);
}, next),
], cb);
}

Expand Down

0 comments on commit 00a5b99

Please sign in to comment.