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

fix: backport 8.0.3 #987

Merged
merged 1 commit into from
Apr 22, 2024
Merged
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
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,10 @@ All notable changes to this project will be documented in this file.
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/), and this project adheres
to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).

## [8.0.3] - 2024-04-22

- Fixes issue with core startup when creation of CUD/app/tenant has partial failure

## [8.0.2] - 2024-03-21

- Fixes userIdMapping queries
Expand Down
2 changes: 1 addition & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ compileTestJava { options.encoding = "UTF-8" }
// }
//}

version = "8.0.2"
version = "8.0.3"


repositories {
Expand Down
2 changes: 1 addition & 1 deletion pluginInterfaceSupported.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"_comment": "contains a list of plugin interfaces branch names that this core supports",
"versions": [
"5.0"
"5.1"
]
}
8 changes: 7 additions & 1 deletion src/main/java/io/supertokens/Main.java
Original file line number Diff line number Diff line change
Expand Up @@ -187,7 +187,7 @@ private void init() throws IOException, StorageQueryException {
}
}
try {
StorageLayer.getBaseStorage(this).initStorage(true);
StorageLayer.getBaseStorage(this).initStorage(true, List.of());
} catch (DbInitException e) {
throw new QuitProgramException(e);
}
Expand All @@ -208,6 +208,12 @@ private void init() throws IOException, StorageQueryException {
// load all configs for each of the tenants.
MultitenancyHelper.getInstance(this).loadConfig(new ArrayList<>());

if (!StorageLayer.isInMemDb(this)) {
// we want to init storage connection once again so that the base storage also contains the right
// tenant identifier set passed to the init. So we call the resetPostConnectCallbackForBaseTenantStorage.
StorageLayer.getBaseStorage(this).close();
}

// init storage layers for each unique db connection based on unique (user pool ID, connection pool ID).
MultitenancyHelper.getInstance(this).loadStorageLayer();
} catch (InvalidConfigException e) {
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/io/supertokens/inmemorydb/Start.java
Original file line number Diff line number Diff line change
Expand Up @@ -175,7 +175,7 @@ public void stopLogging() {
}

@Override
public void initStorage(boolean shouldWait) throws DbInitException {
public void initStorage(boolean shouldWait, List<TenantIdentifier> tenantIdentifiers) throws DbInitException {
if (ConnectionPool.isAlreadyInitialised(this)) {
return;
}
Expand Down
20 changes: 18 additions & 2 deletions src/main/java/io/supertokens/storageLayer/StorageLayer.java
Original file line number Diff line number Diff line change
Expand Up @@ -279,9 +279,25 @@ public static void loadAllTenantStorage(Main main, TenantConfig[] tenants)
Map<ResourceDistributor.KeyClass, ResourceDistributor.SingletonResource> resources =
main.getResourceDistributor()
.getAllResourcesWithResourceKey(RESOURCE_KEY);
for (ResourceDistributor.SingletonResource resource : resources.values()) {

// we are creating this map to find tenantIdentifiers that are associated with each storage.
// when we call the initStorage, the storage instance remembers the tenants that need to be created
// in case error happens. Whenever the connection is restored, the tenant entries are created on that
// storage. If the storage is already live, then it will be a no-op.
Map<Storage, Set<TenantIdentifier>> storageToTenantIdentifiersMap = new HashMap<>();
// Set tenant identifiers handled by each storage instance before initialising them
for (ResourceDistributor.KeyClass key : resources.keySet()) {
if (storageToTenantIdentifiersMap.get(((StorageLayer) resources.get(key)).storage) == null) {
storageToTenantIdentifiersMap.put(((StorageLayer) resources.get(key)).storage, new HashSet<>());
}
storageToTenantIdentifiersMap.get(((StorageLayer) resources.get(key)).storage).add(key.getTenantIdentifier());
}

for (ResourceDistributor.KeyClass key : resources.keySet()) {
ResourceDistributor.SingletonResource resource = resources.get(key);

try {
((StorageLayer) resource).storage.initStorage(false);
((StorageLayer) resource).storage.initStorage(false, new ArrayList<>(storageToTenantIdentifiersMap.get(((StorageLayer) resource).storage)));
((StorageLayer) resource).storage.initFileLogging(
Config.getBaseConfig(main).getInfoLogPath(main),
Config.getBaseConfig(main).getErrorLogPath(main));
Expand Down
2 changes: 1 addition & 1 deletion src/test/java/io/supertokens/test/multitenant/LogTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -148,7 +148,7 @@ public void testLogThatEachLineIsUniqueOnStartup() throws Exception {
uniqueLines.add(line);
}

assertEquals(uniqueLines.size(), lines.length);
assertEquals(uniqueLines.size(), lines.length - 1); // we have 1 repeating line which initialises connection pool

assertEquals(7, Multitenancy.getAllTenants(process.getProcess()).length);

Expand Down
Loading