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

Infinispan, upload schemas on backup clusters #38248

Merged
merged 1 commit into from
Jan 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
6 changes: 6 additions & 0 deletions docs/src/main/asciidoc/infinispan-client-reference.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -174,6 +174,12 @@ public class InfinispanExample {
<2> The client connects to the 'lon-site'.
<3> The client connects to the default site.

By default, Protobuf Schemas will also be uploaded to the backup clusters. However, it might be required to handle
the registration manually as a schema may evolve over time when used in production, so you can
disable this from occurring in each backup site by configuring the
`quarkus.infinispan-client.backup-cluster.YOUR_SITE_NAME.use-schema-registration` to `false`.
The value of this property will be ignored if the `use-schema-registration` global property is `false`.

[NOTE]
====
Cross-site replication is a powerful feature offered by Infinispan that facilitates data backup between clusters
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

public final class MarshallingBuildItem extends SimpleBuildItem {

// holds protostream requierements
// holds protostream requirements
private final Properties properties;

// a marshaller can be defined for different client names
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,8 @@ private void registerSchemaInServer(String infinispanConfigName,
RemoteCache<String, String> protobufMetadataCache = null;
Properties namedProperties = properties.get(infinispanConfigName);
Set<SerializationContextInitializer> initializers = (Set) namedProperties.remove(PROTOBUF_INITIALIZERS);
InfinispanClientRuntimeConfig runtimeConfig = this.infinispanClientsRuntimeConfigHandle.get()
.getInfinispanClientRuntimeConfig(infinispanConfigName);
if (initializers != null) {
for (SerializationContextInitializer initializer : initializers) {
if (protobufMetadataCache == null) {
Expand All @@ -75,6 +77,20 @@ private void registerSchemaInServer(String infinispanConfigName,
}
protobufMetadataCache.put(initializer.getProtoFileName(), initializer.getProtoFile());
}
runtimeConfig.backupCluster.entrySet().forEach(backup -> {
if (backup.getValue().useSchemaRegistration.orElse(true)) {
cacheManager.switchToCluster(backup.getKey());
for (SerializationContextInitializer initializer : initializers) {
RemoteCache<String, String> backupProtobufMetadataCache = null;
if (backupProtobufMetadataCache == null) {
backupProtobufMetadataCache = cacheManager.getCache(
ProtobufMetadataManagerConstants.PROTOBUF_METADATA_CACHE_NAME);
}
backupProtobufMetadataCache.put(initializer.getProtoFileName(), initializer.getProtoFile());
}
cacheManager.switchToDefaultCluster();
}
});
}

for (Map.Entry<Object, Object> property : namedProperties.entrySet()) {
Expand All @@ -92,6 +108,29 @@ private void registerSchemaInServer(String infinispanConfigName,
}
}
}

runtimeConfig.backupCluster.entrySet().forEach(backupConfigEntry -> {
if (backupConfigEntry.getValue().useSchemaRegistration.orElse(true)) {
cacheManager.switchToCluster(backupConfigEntry.getKey());
RemoteCache<String, String> backupProtobufMetadataCache = null;
for (Map.Entry<Object, Object> property : namedProperties.entrySet()) {
Object key = property.getKey();
if (key instanceof String) {
String keyString = (String) key;
if (keyString.startsWith(PROTOBUF_FILE_PREFIX)) {
String fileName = keyString.substring(PROTOBUF_FILE_PREFIX.length());
String fileContents = (String) property.getValue();
if (backupProtobufMetadataCache == null) {
backupProtobufMetadataCache = cacheManager.getCache(
ProtobufMetadataManagerConstants.PROTOBUF_METADATA_CACHE_NAME);
}
backupProtobufMetadataCache.put(fileName, fileContents);
}
}
}
cacheManager.switchToDefaultCluster();
}
});
}

private void initialize(String infinispanConfigName, Map<String, Properties> properties) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -283,6 +283,17 @@ public static class BackupClusterConfig {
// @formatter:on
@ConfigItem(defaultValue = "HASH_DISTRIBUTION_AWARE")
Optional<String> clientIntelligence;

// @formatter:off
/**
* Enables or disables Protobuf generated schemas upload to the backup.
* Set it to 'false' when you need to handle the lifecycle of the Protobuf Schemas on Server side yourself.
* Default is 'true'.
* This setting will be ignored if the Global Setting is set up to false.
*/
// @formatter:on
@ConfigItem(defaultValue = "true")
Optional<Boolean> useSchemaRegistration;
}

@Override
Expand Down
Loading