SOLR-14128: Improve distributed locking around managed schema upgrade process.

This commit is contained in:
Andrzej Bialecki 2020-03-25 22:19:15 +01:00
parent 4f03ce5899
commit b0728ceca6
2 changed files with 37 additions and 33 deletions

View File

@ -77,6 +77,8 @@ Bug Fixes
* SOLR-14347: Autoscaling placement wrong when concurrent replica placements are calculated. (ab) * SOLR-14347: Autoscaling placement wrong when concurrent replica placements are calculated. (ab)
* SOLR-14128: Improve distributed locking around managed schema upgrade process. (ab)
Other Changes Other Changes
--------------------- ---------------------
* SOLR-14197: SolrResourceLoader: marked many methods as deprecated, and in some cases rerouted exiting logic to avoid * SOLR-14197: SolrResourceLoader: marked many methods as deprecated, and in some cases rerouted exiting logic to avoid

View File

@ -321,21 +321,15 @@ public class ManagedIndexSchemaFactory extends IndexSchemaFactory implements Sol
* and no exception will be thrown. * and no exception will be thrown.
*/ */
private void zkUgradeToManagedSchema() { private void zkUgradeToManagedSchema() {
schema.persistManagedSchemaToZooKeeper(true); // Only create, don't update it if it already exists
// After successfully persisting the managed schema, rename the non-managed
// schema znode by appending UPGRADED_SCHEMA_EXTENSION to its name.
if (resourceName.equals(managedSchemaResourceName)) { if (resourceName.equals(managedSchemaResourceName)) {
log.info("On upgrading to managed schema, did not rename non-managed schema " log.info("On upgrading to managed schema, did not rename non-managed schema "
+ resourceName + " because it's the same as the managed schema's name."); + resourceName + " because it's the same as the managed schema's name.");
} else { return;
// Rename the non-managed schema znode in ZooKeeper }
ZkSolrResourceLoader zkLoader = (ZkSolrResourceLoader)loader; final ZkSolrResourceLoader zkLoader = (ZkSolrResourceLoader)loader;
ZkController zkController = zkLoader.getZkController(); final ZkController zkController = zkLoader.getZkController();
SolrZkClient zkClient = zkController.getZkClient(); final SolrZkClient zkClient = zkController.getZkClient();
final String nonManagedSchemaPath = zkLoader.getConfigSetZkPath() + "/" + resourceName; final String lockPath = zkLoader.getConfigSetZkPath() + "/schemaUpgrade.lock";
final String lockPath = nonManagedSchemaPath + ".lock";
boolean locked = false; boolean locked = false;
try { try {
try { try {
@ -345,6 +339,14 @@ public class ManagedIndexSchemaFactory extends IndexSchemaFactory implements Sol
// some other node already started the upgrade, or an error occurred - bail out // some other node already started the upgrade, or an error occurred - bail out
return; return;
} }
schema.persistManagedSchemaToZooKeeper(true); // Only create, don't update it if it already exists
// After successfully persisting the managed schema, rename the non-managed
// schema znode by appending UPGRADED_SCHEMA_EXTENSION to its name.
// Rename the non-managed schema znode in ZooKeeper
final String nonManagedSchemaPath = zkLoader.getConfigSetZkPath() + "/" + resourceName;
try {
ZkCmdExecutor zkCmdExecutor = new ZkCmdExecutor(zkController.getClientTimeout()); ZkCmdExecutor zkCmdExecutor = new ZkCmdExecutor(zkController.getClientTimeout());
if (zkController.pathExists(nonManagedSchemaPath)) { if (zkController.pathExists(nonManagedSchemaPath)) {
// First, copy the non-managed schema znode content to the upgraded schema znode // First, copy the non-managed schema znode content to the upgraded schema znode
@ -376,6 +378,7 @@ public class ManagedIndexSchemaFactory extends IndexSchemaFactory implements Sol
} }
final String msg = "Error persisting managed schema resource " + managedSchemaResourceName; final String msg = "Error persisting managed schema resource " + managedSchemaResourceName;
log.warn(msg, e); // Log as warning and suppress the exception log.warn(msg, e); // Log as warning and suppress the exception
}
} finally { } finally {
if (locked) { if (locked) {
// unlock // unlock
@ -389,7 +392,6 @@ public class ManagedIndexSchemaFactory extends IndexSchemaFactory implements Sol
} }
} }
} }
}
private Object schemaUpdateLock = new Object(); private Object schemaUpdateLock = new Object();
public Object getSchemaUpdateLock() { return schemaUpdateLock; } public Object getSchemaUpdateLock() { return schemaUpdateLock; }