Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[DO NOT MERGE] Partitioned ID Mode #6391

Open
wants to merge 160 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
160 commits
Select commit Hold shift + click to select a range
f8bfcd5
Begin work on PK schema selector
jamesagnew Jul 18, 2024
32f2acd
Merge branch 'master' into ja_20240718_pk_schema_selector
jamesagnew Jul 23, 2024
b3dd2c5
Merge branch 'master' into ja_20240718_pk_schema_selector
jamesagnew Aug 27, 2024
3c40365
Work on generator
jamesagnew Aug 28, 2024
bc8f0b6
Filter working
jamesagnew Aug 28, 2024
0fb7dac
Add tests
jamesagnew Aug 29, 2024
c0647b3
Work on tests
jamesagnew Sep 5, 2024
c911244
Work on contributor
jamesagnew Sep 5, 2024
80d7690
Work
jamesagnew Sep 7, 2024
0c703bb
Tests passing
jamesagnew Sep 7, 2024
2a349b2
Drop unneeded annotation
jamesagnew Sep 9, 2024
5e6d02c
Partition cleanup
jamesagnew Sep 9, 2024
786f2c0
About to merge JpaPid
jamesagnew Sep 9, 2024
0c513f9
Work on IDs
jamesagnew Sep 9, 2024
14faa7c
Merge branch 'master' into ja_20240718_pk_schema_selector
jamesagnew Sep 10, 2024
9e0539d
Tests passing
jamesagnew Sep 10, 2024
052253e
Working on query count tests
jamesagnew Sep 10, 2024
3fabcb6
Ongoing work
jamesagnew Sep 11, 2024
9fc3f04
Ongoing work
jamesagnew Sep 13, 2024
dd2bffa
Merge branch 'master' into ja_20240718_pk_schema_selector
jamesagnew Sep 13, 2024
a1d5b49
Working on tests - Running but about to try removing
jamesagnew Sep 13, 2024
9fa9a5d
More tests passing
jamesagnew Sep 13, 2024
c683cfb
Fix some more tests
jamesagnew Sep 13, 2024
8dcb153
Merge branch 'master' into ja_20240718_pk_schema_selector
jamesagnew Sep 13, 2024
7cc2874
Test fixes
jamesagnew Sep 13, 2024
e119c71
About to add partition ID to selector
jamesagnew Sep 16, 2024
6164a21
Most query count tests passing
jamesagnew Sep 16, 2024
8e20999
Work on tests
jamesagnew Sep 16, 2024
7e6ba07
Working on includes
jamesagnew Sep 18, 2024
fccd483
All conditional tests passing again
jamesagnew Sep 18, 2024
e9177f3
About to modify joins in SQL builder
jamesagnew Sep 20, 2024
ce5bd40
Search generator refactored, and tests passing
jamesagnew Sep 20, 2024
f700a6b
Merge branch 'master' into ja_20240718_pk_schema_selector
jamesagnew Sep 20, 2024
6c1636f
Tag tests done
jamesagnew Sep 20, 2024
1c5546e
Work on tests
jamesagnew Sep 22, 2024
582cac8
Everything operation fixed
jamesagnew Sep 23, 2024
fee0f8b
Clean up PIDs for batch job
jamesagnew Sep 23, 2024
18bf430
Clean up search paging
jamesagnew Sep 23, 2024
f9b0027
Work on expunge service
jamesagnew Sep 23, 2024
0cfd0c3
Work on tests
jamesagnew Sep 24, 2024
70d9205
Test fixes
jamesagnew Sep 24, 2024
6110497
Work on same transaction updates
jamesagnew Sep 24, 2024
153b17e
Work on JPA R4 tests
jamesagnew Sep 25, 2024
0e16a4a
Merge branch 'master' into ja_20240718_pk_schema_selector
jamesagnew Sep 25, 2024
fe72349
Work on tests
jamesagnew Sep 25, 2024
b72a387
Fixes
jamesagnew Sep 25, 2024
8e06416
Work
jamesagnew Oct 2, 2024
380c004
Test fix
jamesagnew Oct 3, 2024
312e692
Work on tests
jamesagnew Oct 3, 2024
cb33399
Cleanup
jamesagnew Oct 3, 2024
6813f6e
Test fixes
jamesagnew Oct 4, 2024
5d35ba7
Test fix
jamesagnew Oct 4, 2024
955afef
Spotless
jamesagnew Oct 4, 2024
5be3600
Merge branch 'master' into ja_20240718_pk_schema_selector
jamesagnew Oct 4, 2024
9b5538e
License headers
jamesagnew Oct 4, 2024
0ba22cc
Merge branch 'ja_20240718_pk_schema_selector' of github.com:jamesagne…
jamesagnew Oct 4, 2024
925d9ca
Test fix
jamesagnew Oct 4, 2024
50686ea
License headers
jamesagnew Oct 4, 2024
91693ba
Merge branch 'ja_20240718_pk_schema_selector' of github.com:hapifhir/…
jamesagnew Oct 4, 2024
7516bc0
Compile fix
jamesagnew Oct 4, 2024
5f0663e
Test fix
jamesagnew Oct 4, 2024
4dc104f
Test fix
jamesagnew Oct 4, 2024
d67d5f4
Test fixes
jamesagnew Oct 4, 2024
d90ae99
Test fixes
jamesagnew Oct 4, 2024
629cd92
Cleanup
jamesagnew Oct 4, 2024
667e121
Test fixes
jamesagnew Oct 4, 2024
f3350dd
Test fixes
jamesagnew Oct 4, 2024
7a48179
Starting to address fixmes
jamesagnew Oct 4, 2024
3071f05
Spotless
jamesagnew Oct 4, 2024
fd57042
More test cleanup
jamesagnew Oct 4, 2024
f00ef9f
Test cleanup
jamesagnew Oct 4, 2024
bfe9562
Test fixes
jamesagnew Oct 4, 2024
137ce84
Test fixes
jamesagnew Oct 4, 2024
1e9b816
Spotless
jamesagnew Oct 4, 2024
5ac7ee6
Test cleanup
jamesagnew Oct 4, 2024
465be01
Merge branch 'ja_20240718_pk_schema_selector' of github.com:hapifhir/…
jamesagnew Oct 4, 2024
207c94b
Test fix
jamesagnew Oct 4, 2024
43b1157
Deal with test failures
jamesagnew Oct 4, 2024
a865d34
Spotless
jamesagnew Oct 4, 2024
00d0b01
Test fixes
jamesagnew Oct 5, 2024
e44abcf
About to modify RESOURCE_LOOKUP cache
jamesagnew Oct 5, 2024
bc770ab
Test cleanup
jamesagnew Oct 5, 2024
dfdae22
Intermittent test fix
jamesagnew Oct 5, 2024
210ae10
Try to resolve intermittent
jamesagnew Oct 5, 2024
98cf06c
More test work
jamesagnew Oct 5, 2024
8b8f428
Test fixing
jamesagnew Oct 6, 2024
2848573
Add tests
jamesagnew Oct 6, 2024
63ab7b5
Spotless
jamesagnew Oct 6, 2024
c3e7bac
Add troubleshooting logs
jamesagnew Oct 7, 2024
be4cbc3
Add test logging
jamesagnew Oct 7, 2024
e446195
More test logging
jamesagnew Oct 7, 2024
53bbec2
Test fix
jamesagnew Oct 7, 2024
dee216c
Test fixes
jamesagnew Oct 7, 2024
786854d
Test fix
jamesagnew Oct 7, 2024
e1d1bb5
Test fixes
jamesagnew Oct 7, 2024
3ecfd24
Test cleanup
jamesagnew Oct 7, 2024
526fa22
Test cleanup
jamesagnew Oct 7, 2024
6cdef19
Test fix
jamesagnew Oct 7, 2024
3cd0f16
Test fix
jamesagnew Oct 7, 2024
53675c3
Merge branch 'master' into ja_20240718_pk_schema_selector
jamesagnew Oct 7, 2024
2409f9c
Fixes
jamesagnew Oct 8, 2024
69b56d0
Add tests
jamesagnew Oct 9, 2024
79a5f3f
Test cleanup
jamesagnew Oct 9, 2024
fb4e89a
Remove stale test
jamesagnew Oct 9, 2024
1a3d2eb
Test fix
jamesagnew Oct 9, 2024
e1c6f8c
Imports cleaniup
jamesagnew Oct 9, 2024
2af3fa6
Work on migrations
jamesagnew Oct 10, 2024
6eff590
Work on migrations
jamesagnew Oct 10, 2024
c0fd37f
Work on PKs
jamesagnew Oct 13, 2024
4ede08a
Merge branch 'master' into ja_20240718_pk_schema_selector
jamesagnew Oct 13, 2024
214ea0f
Work on tests
jamesagnew Oct 14, 2024
d788b9c
Cleanup
jamesagnew Oct 15, 2024
c6e8cb5
Test fix
jamesagnew Oct 15, 2024
2b8da27
Test fix
jamesagnew Oct 15, 2024
91bd50a
Spotless
jamesagnew Oct 15, 2024
64df816
Test fixes
jamesagnew Oct 15, 2024
96b10a4
Test fix
jamesagnew Oct 15, 2024
d1358e3
Merge branch 'master' into ja_20240718_pk_schema_selector
jamesagnew Oct 15, 2024
6642473
Test fixes
jamesagnew Oct 15, 2024
3bb91bb
Test fix
jamesagnew Oct 15, 2024
911679b
t fix
jamesagnew Oct 15, 2024
9a496bd
Test fixes
jamesagnew Oct 15, 2024
5fe124d
Test fix
jamesagnew Oct 15, 2024
6fbe533
Merge branch 'master' into ja_20240718_pk_schema_selector
jamesagnew Oct 16, 2024
ab62e83
Test fixes
jamesagnew Oct 16, 2024
e6fc91c
Add test method
jamesagnew Oct 16, 2024
8bebdc6
Merge branch 'master' into ja_20240718_pk_schema_selector
jamesagnew Oct 16, 2024
af57a77
Test cleanup
jamesagnew Oct 16, 2024
2df09b6
Test fixes
jamesagnew Oct 17, 2024
03a94c3
Cleanup
jamesagnew Oct 17, 2024
82af5ac
Test fixes
jamesagnew Oct 17, 2024
f1bc5d5
Merge branch 'master' into ja_20240718_pk_schema_selector
jamesagnew Oct 17, 2024
fb779fd
Cleanup
jamesagnew Oct 17, 2024
e681e8f
Test cleanup
jamesagnew Oct 17, 2024
6a3a493
Test fix
jamesagnew Oct 17, 2024
34eb229
Add migrator support
jamesagnew Oct 17, 2024
8ed65f7
More test work
jamesagnew Oct 17, 2024
bfbd523
Spotless
jamesagnew Oct 17, 2024
125ccd1
Add header
jamesagnew Oct 17, 2024
8384126
Merge branch 'ja_20240718_pk_schema_selector' of github.com:hapifhir/…
jamesagnew Oct 17, 2024
eff6882
License header
jamesagnew Oct 18, 2024
2561835
Merge branch 'master' into ja_20240718_pk_schema_selector
jamesagnew Oct 18, 2024
58c6297
Merge branch 'master' into ja_20240718_pk_schema_selector
jamesagnew Oct 18, 2024
e911431
Merge branch 'master' into ja_20240718_pk_schema_selector
jamesagnew Oct 18, 2024
05dddc9
Test fix
jamesagnew Oct 18, 2024
458eeda
MDM test fixes
jamesagnew Oct 18, 2024
5b88dc8
Merge branch 'master' into ja_20240718_pk_schema_selector
jamesagnew Oct 18, 2024
68ee0f7
Test fix
jamesagnew Oct 18, 2024
0a9688e
Merge branch 'master' into ja_20240718_pk_schema_selector
jamesagnew Oct 18, 2024
9138d9d
Add tests
jamesagnew Oct 21, 2024
f1e0619
Cleanup
jamesagnew Oct 22, 2024
7cbbb37
Compile fix
jamesagnew Oct 22, 2024
7792a83
Spotless
jamesagnew Oct 22, 2024
71ca533
Work on docs
jamesagnew Oct 22, 2024
f656812
Merge branch 'master' into ja_20240718_pk_schema_selector
jamesagnew Oct 22, 2024
371cfbd
Cleanup
jamesagnew Oct 24, 2024
ba67a9b
Merge branch 'master' into ja_20240718_pk_schema_selector
jamesagnew Oct 29, 2024
a5a4462
Add partitioned test
jamesagnew Oct 30, 2024
77a2796
Work on tests
jamesagnew Nov 7, 2024
965cf1d
Rename JpaPidValueTuples
jamesagnew Nov 7, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,18 @@
import java.util.Map;

public class HistorySearchDateRangeParam extends DateRangeParam {
/**
* Constructor
*
* @since 8.0.0
*/
public HistorySearchDateRangeParam() {
this(Map.of(), new DateRangeParam(), null);
}

/**
* Constructor
*/
public HistorySearchDateRangeParam(
Map<String, String[]> theParameters, DateRangeParam theDateRange, Integer theOffset) {
super(theDateRange);
Expand Down
20 changes: 20 additions & 0 deletions hapi-fhir-base/src/main/java/ca/uhn/fhir/util/FileUtil.java
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,13 @@
*/
package ca.uhn.fhir.util;

import ca.uhn.fhir.rest.server.exceptions.InternalErrorException;
import org.apache.commons.io.IOUtils;

import java.io.File;
import java.io.FileReader;
import java.io.IOException;
import java.nio.charset.StandardCharsets;
import java.text.DecimalFormat;

public class FileUtil {
Expand All @@ -33,4 +40,17 @@ public static String formatFileSize(long theBytes) {
digitGroups = Math.min(digitGroups, UNITS.length - 1);
return new DecimalFormat("###0.#").format(theBytes / Math.pow(1024, digitGroups)) + " " + UNITS[digitGroups];
}

/**
* Loads the contents of a File as a UTF-8 encoded string, and wraps any exceptions in an unchecked exception
*
* @throws InternalErrorException If any IOException occurs
*/
public static String loadFileAsString(File theFile) throws InternalErrorException {
try (FileReader fr = new FileReader(theFile, StandardCharsets.UTF_8)) {
return IOUtils.toString(fr);
} catch (IOException e) {
throw new InternalErrorException(e);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,14 @@

import ca.uhn.fhir.context.FhirContext;
import ca.uhn.fhir.jpa.provider.BaseJpaSystemProvider;
import ca.uhn.fhir.rest.server.exceptions.InternalErrorException;
import ca.uhn.fhir.system.HapiSystemProperties;
import ca.uhn.fhir.test.utilities.RestServerR4Helper;
import ca.uhn.fhir.test.utilities.TlsAuthenticationTestHelper;
import ca.uhn.fhir.util.ParametersUtil;
import ca.uhn.test.util.LogbackTestExtension;
import ca.uhn.test.util.LogbackTestExtensionAssert;
import ch.qos.logback.classic.Level;
import ch.qos.logback.classic.Logger;
import org.hl7.fhir.instance.model.api.IBaseParameters;
import org.junit.jupiter.api.BeforeEach;
Expand Down Expand Up @@ -40,9 +42,8 @@ class ReindexTerminologyCommandTest {
public final RestServerR4Helper myRestServerR4Helper = RestServerR4Helper.newInitialized();
@RegisterExtension
public TlsAuthenticationTestHelper myTlsAuthenticationTestHelper = new TlsAuthenticationTestHelper();

// Deliberately not registered - we manually run this later because App startup resets the logging.
LogbackTestExtension myAppLogCapture;
@RegisterExtension
public LogbackTestExtension myLogbackTestExtension = new LogbackTestExtension(BaseApp.ourLog);

static {
HapiSystemProperties.enableTestMode();
Expand All @@ -69,7 +70,7 @@ public void testProviderMethodInvoked(boolean theIncludeTls) {
);
runAppWithStartupHook(args, getLoggingStartupHook());

LogbackTestExtensionAssert.assertThat(myAppLogCapture).doesNotHaveMessage(FAILURE_MESSAGE);
LogbackTestExtensionAssert.assertThat(myLogbackTestExtension).doesNotHaveMessage(FAILURE_MESSAGE);
}

@ParameterizedTest
Expand Down Expand Up @@ -131,7 +132,7 @@ public void testHandleUnexpectedResponse(boolean theIncludeTls) {
);
runAppWithStartupHook(args, getLoggingStartupHook());

LogbackTestExtensionAssert.assertThat(myAppLogCapture)
LogbackTestExtensionAssert.assertThat(myLogbackTestExtension)
.hasMessage(FAILURE_MESSAGE)
.hasMessage("Internal error. Command result unknown. Check system logs for details");
}
Expand All @@ -156,7 +157,7 @@ public void testHandleServiceError(boolean theIncludeTls) {
);
runAppWithStartupHook(args, getLoggingStartupHook());

LogbackTestExtensionAssert.assertThat(myAppLogCapture)
LogbackTestExtensionAssert.assertThat(myLogbackTestExtension)
.hasMessage(FAILURE_MESSAGE)
.hasMessage("Freetext service is not configured. Operation didn't run.");
}
Expand All @@ -176,8 +177,11 @@ static void runAppWithStartupHook(String[] args, Consumer<BaseApp> startupHook)
*/
Consumer<BaseApp> getLoggingStartupHook() {
return (unused) -> {
myAppLogCapture = new LogbackTestExtension((Logger) BaseApp.ourLog);
myAppLogCapture.setUp();
try {
myLogbackTestExtension.reRegister();
} catch (Exception e) {
throw new InternalErrorException(e);
}
};
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,7 @@ page.server_jpa_partitioning.partitioning=Partitioning and Multitenancy
page.server_jpa_partitioning.partition_interceptor_examples=Partition Interceptor Examples
page.server_jpa_partitioning.partitioning_management_operations=Partitioning Management Operations
page.server_jpa_partitioning.enabling_in_hapi_fhir=Enabling Partitioning in HAPI FHIR
page.server_jpa.partitioning.partitioned_id_mode=Partitioned ID Mode

section.server_jpa_batch.title=JPA Server: Batch Processing
page.server_jpa_batch.introduction=Batch Introduction
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
# Partitioned ID Mode Introduction --EXPERIMENTAL--

HAPI FHIR 5.0.0 introduced partitioning to the JPA server. In the current partitioning design, each resource-specific table (i.e. each table in the database schema where each row pertains to a single FHIR resource) has two new columns: `PARTITION_ID`, and `PARTITION_DATE`.

The `PARTITION_DATE` column may be set by user code, but it otherwise untouched by HAPI FHIR. The `PARTITION_ID` column is the main partitioning mechanism. It uses an arbitrary Integer value to demote the partition associated with an individual resource.

### Limitations of the Original Design

The Partition ID was added as a column to the end of many of the default HAPI FHIR database indexes, meaning that searches could take advantage of partition IDs if they were present, but would also perform well if partitioning was not being used.

The original partitioning design also introduced the concept of the _Default Partition_, which is a partition used to store infrastructure resources that are not inherently partitionable. The ID fot eh default partition is configurable, but is set by default to _NULL_.

Although this new partitioning mode unlocked a number of great use cases for HAPI FHIR users (including multitenancy, better scalability, data segmentation, etc.) several fundamental limitations in the design have become apparent over time:

* The Partition ID is not actually a part of the row identities (ie. the Primary Key and Foreign Key )

# Partitioned ID Mode

The HAPI FHIR 8.0.0 JPA server introduces a new experimental mode called Partitioned ID Mode.

40 changes: 40 additions & 0 deletions hapi-fhir-jpa-hibernate-services/pom.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>ca.uhn.hapi.fhir</groupId>
<artifactId>hapi-fhir</artifactId>
<version>7.7.0-SNAPSHOT</version>
</parent>

<artifactId>hapi-fhir-jpa-hibernate-services</artifactId>

<packaging>jar</packaging>

<name>HAPI FHIR JPA Hibernate Services</name>


<dependencies>
<dependency>
<groupId>ca.uhn.hapi.fhir</groupId>
<artifactId>hapi-fhir-base</artifactId>
<version>${project.version}</version>
</dependency>
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-api</artifactId>
</dependency>
<dependency>
<groupId>org.hibernate.orm</groupId>
<artifactId>hibernate-core</artifactId>
</dependency>
<dependency>
<groupId>com.google.guava</groupId>
<artifactId>guava</artifactId>
</dependency>
<dependency>
<groupId>jakarta.annotation</groupId>
<artifactId>jakarta.annotation-api</artifactId>
</dependency>
</dependencies>
</project>
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
package ca.uhn.hapi.fhir.sql.hibernatesvc;

import org.hibernate.service.Service;

/**
* A hibernate {@link Service} which provides the HAPI FHIR Storage Settings.
*/
public class HapiHibernateDialectSettingsService implements Service {

private boolean myTrimConditionalIdsFromPrimaryKeys;

public boolean isTrimConditionalIdsFromPrimaryKeys() {
return myTrimConditionalIdsFromPrimaryKeys;
}

public void setTrimConditionalIdsFromPrimaryKeys(boolean theTrimConditionalIdsFromPrimaryKeys) {
myTrimConditionalIdsFromPrimaryKeys = theTrimConditionalIdsFromPrimaryKeys;
}
}
Loading
Loading