Fix possible race condition applying schemas
Found an instance where two of these fired too close together, and caused a fatal error. Use a write lock, and then catch the schema.apply function in case it fails anyways.
This commit is contained in:
		@@ -197,6 +197,8 @@ def entrypoint():
 | 
				
			|||||||
        os.execv(sys.argv[0], sys.argv)
 | 
					        os.execv(sys.argv[0], sys.argv)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    # Validate the schema
 | 
					    # Validate the schema
 | 
				
			||||||
 | 
					    with zkhandler.writelock("base.schema.version"):
 | 
				
			||||||
 | 
					        sleep(0.5)
 | 
				
			||||||
        pvcnoded.util.zookeeper.validate_schema(logger, zkhandler)
 | 
					        pvcnoded.util.zookeeper.validate_schema(logger, zkhandler)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    # Define a cleanup function
 | 
					    # Define a cleanup function
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -94,7 +94,10 @@ def validate_schema(logger, zkhandler):
 | 
				
			|||||||
    # Validate our schema against the active version
 | 
					    # Validate our schema against the active version
 | 
				
			||||||
    if not zkhandler.schema.validate(zkhandler, logger):
 | 
					    if not zkhandler.schema.validate(zkhandler, logger):
 | 
				
			||||||
        logger.out("Found schema violations, applying", state="i")
 | 
					        logger.out("Found schema violations, applying", state="i")
 | 
				
			||||||
 | 
					        try:
 | 
				
			||||||
            zkhandler.schema.apply(zkhandler)
 | 
					            zkhandler.schema.apply(zkhandler)
 | 
				
			||||||
 | 
					        except Exception as e:
 | 
				
			||||||
 | 
					            logger.out(f"Failed to apply schema updates: {e}", state="w")
 | 
				
			||||||
    else:
 | 
					    else:
 | 
				
			||||||
        logger.out("Schema successfully validated", state="o")
 | 
					        logger.out("Schema successfully validated", state="o")
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 
 | 
				
			|||||||
		Reference in New Issue
	
	Block a user