|
1 | | -import * as crypto from 'crypto'; |
2 | 1 | import * as constants from '../constants'; |
3 | 2 | import * as VersionIDUtils from '../versioning/VersionID'; |
4 | 3 | import { VersioningConstants } from '../versioning/constants'; |
@@ -49,6 +48,7 @@ export type ReplicationInfo = { |
49 | 48 | /** @deprecated in favor of per-backend dataStoreVersionId for multi-destination. */ |
50 | 49 | dataStoreVersionId?: string; |
51 | 50 | isNFS?: boolean; |
| 51 | + isReplica?: boolean; |
52 | 52 | }; |
53 | 53 |
|
54 | 54 | export type ObjectMDTag = { |
@@ -260,6 +260,7 @@ export default class ObjectMD { |
260 | 260 | storageType: undefined, |
261 | 261 | dataStoreVersionId: undefined, |
262 | 262 | isNFS: undefined, |
| 263 | + isReplica: undefined, |
263 | 264 | }, |
264 | 265 | dataStoreName: '', |
265 | 266 | originOp: '', |
@@ -1168,6 +1169,27 @@ export default class ObjectMD { |
1168 | 1169 | return this; |
1169 | 1170 | } |
1170 | 1171 |
|
| 1172 | + /** |
| 1173 | + * Mark this object as the result of a replication write (replica), |
| 1174 | + * as opposed to a write originating from a user request. |
| 1175 | + * |
| 1176 | + * @param isReplica - true if this object was written by replication |
| 1177 | + * @return itself |
| 1178 | + */ |
| 1179 | + setReplicationIsReplica(isReplica: boolean) { |
| 1180 | + this._data.replicationInfo.isReplica = isReplica; |
| 1181 | + return this; |
| 1182 | + } |
| 1183 | + |
| 1184 | + /** |
| 1185 | + * Get whether this object was written by replication (replica). |
| 1186 | + * @return true if this object is a replica |
| 1187 | + */ |
| 1188 | + getReplicationIsReplica(): boolean { |
| 1189 | + return this._data.replicationInfo.isReplica === true |
| 1190 | + || this._data.replicationInfo.status === 'REPLICA'; |
| 1191 | + } |
| 1192 | + |
1171 | 1193 | getReplicationSiteStatus(key: BackendKey): string | undefined { |
1172 | 1194 | return this._findBackend(key)?.status; |
1173 | 1195 | } |
@@ -1348,35 +1370,28 @@ export default class ObjectMD { |
1348 | 1370 | } |
1349 | 1371 |
|
1350 | 1372 | /** |
1351 | | - * Create or update the microVersionId field |
1352 | | - * |
1353 | | - * This field can be used to force an update in MongoDB. This can |
1354 | | - * be needed in the following cases: |
1355 | | - * |
1356 | | - * - in case no other metadata field changes |
1357 | | - * |
1358 | | - * - to detect a change when fields change but object version does |
1359 | | - * not change e.g. when ingesting a putObjectTagging coming from |
1360 | | - * S3C to Zenko |
1361 | | - * |
1362 | | - * - to manage conflicts during concurrent updates, using |
1363 | | - * conditions on the microVersionId field. |
1364 | | - * |
1365 | | - * It's a field of 16 hexadecimal characters randomly generated |
1366 | | - * |
| 1373 | + * Update the microVersionId |
| 1374 | + * |
| 1375 | + * This field can be used to force an update in MongoDB when no other |
| 1376 | + * metadata field changes, to detect a change for CRR, |
| 1377 | + * and to manage conflicts during concurrent updates using conditions on this field. |
| 1378 | + * |
| 1379 | + * @param instanceId - instance identifier (e.g. config.instanceId) |
| 1380 | + * @param replicationGroupId - replication group ID (e.g. config.replicationGroupId) |
1367 | 1381 | * @return itself |
1368 | 1382 | */ |
1369 | | - updateMicroVersionId() { |
1370 | | - this._data.microVersionId = crypto.randomBytes(8).toString('hex'); |
| 1383 | + updateMicroVersionId(instanceId: string, replicationGroupId: string) { |
| 1384 | + this._data.microVersionId = VersionIDUtils.generateVersionId(instanceId, replicationGroupId); |
| 1385 | + return this; |
1371 | 1386 | } |
1372 | 1387 |
|
1373 | 1388 | /** |
1374 | | - * Get the microVersionId field, or null if not set |
| 1389 | + * Get the microVersionId field, or undefined if not set |
1375 | 1390 | * |
1376 | | - * @return the microVersionId field if exists, or {null} if it does not exist |
| 1391 | + * @return the microVersionId field if set, or undefined if not |
1377 | 1392 | */ |
1378 | 1393 | getMicroVersionId() { |
1379 | | - return this._data.microVersionId || null; |
| 1394 | + return this._data.microVersionId || undefined; |
1380 | 1395 | } |
1381 | 1396 |
|
1382 | 1397 | /** |
|
0 commit comments