Skip to content

Commit ba5ce67

Browse files
authored
Merge pull request #3732 from IBM/issue-3731-ra
Issue 3731 add reindex force option to fhir-bucket
2 parents ac40df1 + 9362e99 commit ba5ce67

5 files changed

Lines changed: 50 additions & 9 deletions

File tree

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@ fhirschema.log
3939

4040
# Don't import pom backups
4141
**/pom.xml.versionsBackup
42+
dependency-reduced-pom.xml
4243

4344
# Maven config
4445
.mvn/

fhir-bucket/README.md

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,13 +48,32 @@ The value for `--reindex-concurrent-requests` can be increased/decreased to maxi
4848

4949
If the client-side-driven reindex is unable to be completed due to an error or timeout, the reindex can be resumed by using the `--reindex-start-with-index-id` parameter. If this needs to be done, first check the fhir-bucket log and find the first index ID that was not successful. Then, by specifying that index ID for the value of `--reindex-start-with-index-id` when starting the client-side-driven reindex, the reindex is resumed from that point, instead of starting completely over.
5050

51+
When reindexing, the server compares a hash of the parameter values extracted from the resource with the value of the parameter hash last stored in the database. If the values are equal, the reindex operation skips further processing of the resource which can save a significant amount of time in cases where a search parameter configuration change affects only a subset of resources or resource types. However, some schema upgrades may change the way search parameters are stored and indexed. In such a case, use the `--reindex-force` option. When given, this instructs the reindex operation to ignore the parameter hash comparison and instead always store the new parameters. For example:
52+
53+
```
54+
java \
55+
-Djava.util.logging.config.file=logging.properties \
56+
-jar "${JAR}" \
57+
--fhir-properties your-fhir-server.properties \
58+
--tenant-name your-tenant-name \
59+
--max-concurrent-fhir-requests 100 \
60+
--no-scan \
61+
--reindex-tstamp 2020-12-01T00:00:00Z \
62+
--reindex-resource-count 50 \
63+
--reindex-concurrent-requests 20 \
64+
--reindex-client-side-driven \
65+
--reindex-force
66+
```
67+
68+
5169
| Property | Description |
5270
|---|---|
5371
| `--reindex-tstamp` | 'yyyy-MM-dd' or ISO 8601 dateTime which the reindex is using to start the operation|
5472
| `--reindex-resource-count` | The count to index in a single request. e.g. 100 with a maximum value is 1000.|
5573
| `--reindex-concurrent-requests` | The simultaneous requests used to execute concurrently |
5674
| `--reindex-client-side-driven` | Switches between Client driven $reindex and Server side driven reindex. True or false, false by default. |
5775
| `--reindex-start-with-index-id` | A index-id used with Client driven $reindex to drive reindexing from the Client side.|
76+
| `--reindex-force` | Force the reindex operation to replace the parameters, even if the parameter hash matches.|
5877
| `--fhir-properties` | Properties file for the IBM FHIR Server |
5978

6079
### IBM FHIR Server Properties - The FHIR Properties

fhir-bucket/src/main/java/com/ibm/fhir/bucket/app/Main.java

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -241,6 +241,9 @@ public class Main {
241241
// How many reindex calls should we run in parallel
242242
private int reindexConcurrentRequests = 1;
243243

244+
// Force reindex even if parameter hash matches
245+
private boolean reindexForce = false;
246+
244247
// The number of patients to fetch into the buffer
245248
private int patientBufferSize = 500000;
246249

@@ -511,6 +514,9 @@ public void parseArgs(String[] args) {
511514
throw new IllegalArgumentException("missing value for --reindex-resource-count");
512515
}
513516
break;
517+
case "--reindex-force":
518+
this.reindexForce = true;
519+
break;
514520
case "--reindex-concurrent-requests":
515521
if (i < args.length + 1) {
516522
this.reindexConcurrentRequests = Integer.parseInt(args[++i]);
@@ -1136,9 +1142,9 @@ protected void scanAndLoad() {
11361142
*/
11371143
private void doReindex() {
11381144
if (this.clientSideDrivenReindex) {
1139-
this.driveReindexOperation = new ClientDrivenReindexOperation(fhirClient, reindexConcurrentRequests, reindexTstampParam, reindexResourceCount, reindexStartWithIndexId);
1145+
this.driveReindexOperation = new ClientDrivenReindexOperation(fhirClient, reindexConcurrentRequests, reindexTstampParam, reindexResourceCount, reindexStartWithIndexId, reindexForce);
11401146
} else {
1141-
this.driveReindexOperation = new ServerDrivenReindexOperation(fhirClient, reindexConcurrentRequests, reindexTstampParam, reindexResourceCount);
1147+
this.driveReindexOperation = new ServerDrivenReindexOperation(fhirClient, reindexConcurrentRequests, reindexTstampParam, reindexResourceCount, reindexForce);
11421148
}
11431149
this.driveReindexOperation.init();
11441150

fhir-bucket/src/main/java/com/ibm/fhir/bucket/reindex/ClientDrivenReindexOperation.java

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* (C) Copyright IBM Corp. 2021
2+
* (C) Copyright IBM Corp. 2021, 2022
33
*
44
* SPDX-License-Identifier: Apache-2.0
55
*/
@@ -44,6 +44,7 @@ public class ClientDrivenReindexOperation extends DriveReindexOperation {
4444
private static final String NOT_MODIFIED_AFTER_PARAM = "notModifiedAfter";
4545
private static final String AFTER_INDEX_ID_PARAM = "afterIndexId";
4646
private static final String INDEX_IDS_PARAM = "indexIds";
47+
private static final String FORCE_PARAM = "force";
4748
private static final int MAX_RETRIEVE_COUNT = 1000;
4849
private static final int OFFER_TIMEOUT_IN_SEC = 30;
4950
private static final int POLL_TIMEOUT_IN_SEC = 5;
@@ -88,21 +89,26 @@ public class ClientDrivenReindexOperation extends DriveReindexOperation {
8889
// Number of threads currently running
8990
private AtomicInteger currentlyRunning = new AtomicInteger();
9091

92+
// Include the force parameter in the reindex operation request
93+
private final boolean force;
94+
9195
/**
9296
* Public constructor.
9397
* @param fhirClient the FHIR client
9498
* @param maxConcurrentRequests the number of threads to spin up
9599
* @param reindexTimestamp timestamp the reindex began
96100
* @param maxResourceCount resources processed per request per thread
97101
* @param startWithIndexId index ID from which to start, or null
102+
* @param force force the reindex even if the parameter hash matches
98103
*/
99-
public ClientDrivenReindexOperation(FHIRBucketClient fhirClient, int maxConcurrentRequests, String reindexTimestamp, int maxResourceCount, String startWithIndexId) {
104+
public ClientDrivenReindexOperation(FHIRBucketClient fhirClient, int maxConcurrentRequests, String reindexTimestamp, int maxResourceCount, String startWithIndexId, boolean force) {
100105
this.fhirClient = fhirClient;
101106
this.maxConcurrentRequests = maxConcurrentRequests;
102107
this.reindexTimestamp = reindexTimestamp;
103108
this.maxResourceCount = maxResourceCount;
104109
this.blockingQueue = new LinkedBlockingDeque<>(MAX_RETRIEVE_COUNT + (maxResourceCount * maxConcurrentRequests));
105110
this.inProgressIndexIds = Collections.newSetFromMap(new ConcurrentHashMap<String, Boolean>(maxResourceCount * maxConcurrentRequests));
111+
this.force = force;
106112
if (startWithIndexId != null) {
107113
// Subtract 1 since the $retrieve-index operation retrieves index IDs after a specified index ID
108114
this.lastIndexId = String.valueOf(Long.parseLong(startWithIndexId) - 1);
@@ -427,6 +433,7 @@ private boolean callReindexOperation(String indexIds) {
427433

428434
Builder builder = Parameters.builder();
429435
builder.parameter(Parameter.builder().name(str(INDEX_IDS_PARAM)).value(str(indexIds)).build());
436+
builder.parameter(Parameter.builder().name(str(FORCE_PARAM)).value(true).build());
430437
Parameters parameters = builder.build();
431438
String requestBody = FHIRBucketClientUtil.resourceToString(parameters);
432439

fhir-bucket/src/main/java/com/ibm/fhir/bucket/reindex/ServerDrivenReindexOperation.java

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* (C) Copyright IBM Corp. 2020, 2021
2+
* (C) Copyright IBM Corp. 2020, 2022
33
*
44
* SPDX-License-Identifier: Apache-2.0
55
*/
@@ -58,20 +58,28 @@ public class ServerDrivenReindexOperation extends DriveReindexOperation {
5858

5959
/**
6060
* Public constructor
61+
*
6162
* @param client the FHIR client
6263
* @param maxConcurrentRequests the number of threads to spin up
64+
* @param tstampParam
65+
* @param resourceCountParam
66+
* @param force
6367
*/
64-
public ServerDrivenReindexOperation(FHIRBucketClient fhirClient, int maxConcurrentRequests, String tstampParam, int resourceCountParam) {
68+
public ServerDrivenReindexOperation(FHIRBucketClient fhirClient, int maxConcurrentRequests, String tstampParam, int resourceCountParam, boolean force) {
6569
this.fhirClient = fhirClient;
6670
this.maxConcurrentRequests = maxConcurrentRequests;
6771

68-
Parameters parameters = Parameters.builder()
72+
Parameters.Builder builder = Parameters.builder()
6973
.parameter(Parameter.builder().name(str("tstamp")).value(str(tstampParam)).build())
7074
.parameter(Parameter.builder().name(str("resourceCount")).value(intValue(resourceCountParam)).build())
71-
.build();
75+
;
76+
77+
if (force) {
78+
builder.parameter(Parameter.builder().name(str("force")).value(true).build());
79+
}
7280

7381
// Serialize into the requestBody string used by all the threads
74-
this.requestBody = FHIRBucketClientUtil.resourceToString(parameters);
82+
this.requestBody = FHIRBucketClientUtil.resourceToString(builder.build());
7583

7684
if (logger.isLoggable(Level.FINE)) {
7785
logger.fine("Reindex request parameters: " + requestBody);

0 commit comments

Comments
 (0)