public static void logParticipatingHostCount ( long txnId , int participantCount ) { ZooKeeper zk = VoltDB . instance ( ) . getHostMessenger ( ) . getZK ( ) ; final String snapshotPath = VoltZK . completed_snapshots + "/" + txnId ; boolean success = false ; while ( ! success ) { Stat stat = new Stat ( ) ; byte data [ ] = null ; try { data = zk . getData ( snapshotPath , false , stat ) ; } catch ( KeeperException e ) { if ( e . code ( ) == KeeperException . Code . NONODE ) { // If snapshot creation failed for some reason, the node won't exist. ignore return ; } VoltDB . crashLocalVoltDB ( "Failed to get snapshot completion node" , true , e ) ; } catch ( InterruptedException e ) { VoltDB . crashLocalVoltDB ( "Interrupted getting snapshot completion node" , true , e ) ; } if ( data == null ) { VoltDB . crashLocalVoltDB ( "Data should not be null if the node exists" , false , null ) ; } try { JSONObject jsonObj = new JSONObject ( new String ( data , Charsets . UTF_8 ) ) ; if ( jsonObj . getLong ( "txnId" ) != txnId ) { VoltDB . crashLocalVoltDB ( "TxnId should match" , false , null ) ; } int hostCount = jsonObj . getInt ( "hostCount" ) ; // +1 because hostCount was initialized to -1 jsonObj . put ( "hostCount" , hostCount + participantCount + 1 ) ; zk . setData ( snapshotPath , jsonObj . toString ( 4 ) . getBytes ( Charsets . UTF_8 ) , stat . getVersion ( ) ) ; } catch ( KeeperException . BadVersionException e ) { continue ; } catch ( Exception e ) { VoltDB . crashLocalVoltDB ( "This ZK call should never fail" , true , e ) ; } success = true ; } }
Once participating host count is set SnapshotCompletionMonitor can check this ZK node to determine whether the snapshot has finished or not .