66import org .zstack .core .cloudbus .CloudBus ;
77import org .zstack .core .cloudbus .CloudBusCallBack ;
88import org .zstack .core .cloudbus .ResourceDestinationMaker ;
9+ import org .zstack .core .config .GlobalConfigUpdateExtensionPoint ;
910import org .zstack .core .db .Q ;
1011import org .zstack .core .thread .PeriodicTask ;
1112import org .zstack .core .thread .ThreadFacade ;
2021import org .zstack .header .vm .additions .VmHostFileType ;
2122import org .zstack .header .vm .additions .VmHostFileVO ;
2223import org .zstack .header .vm .additions .VmHostFileVO_ ;
24+ import org .zstack .kvm .KVMGlobalConfig ;
2325import org .zstack .utils .Utils ;
2426import org .zstack .utils .logging .CLogger ;
2527
3335public class VmHostFileTracker implements Component {
3436 private static final CLogger logger = Utils .getLogger (VmHostFileTracker .class );
3537
36- private static final long SYNC_INTERVAL_SECONDS = TimeUnit .MINUTES .toSeconds (30 );
37- private static final int SYNC_CONCURRENCY = 5 ;
38-
3938 @ Autowired
4039 private ThreadFacade threadFacade ;
4140 @ Autowired
@@ -52,6 +51,34 @@ public boolean start() {
5251 return true ;
5352 }
5453
54+ submitTrackerTask ();
55+
56+ GlobalConfigUpdateExtensionPoint listener = (oldConfig , newConfig ) -> {
57+ logger .debug (String .format ("%s changed from %s to %s, restarting vm-host-file-tracker" ,
58+ newConfig .getCanonicalName (), oldConfig .value (), newConfig .value ()));
59+ submitTrackerTask ();
60+ };
61+
62+ KVMGlobalConfig .VM_HOST_FILE_SYNC_INTERVAL .installUpdateExtension (listener );
63+ KVMGlobalConfig .VM_HOST_FILE_SYNC_CONCURRENCY .installUpdateExtension (listener );
64+
65+ return true ;
66+ }
67+
68+ @ Override
69+ public boolean stop () {
70+ if (trackerThread != null ) {
71+ trackerThread .cancel (true );
72+ }
73+ return true ;
74+ }
75+
76+ private synchronized void submitTrackerTask () {
77+ if (trackerThread != null ) {
78+ trackerThread .cancel (true );
79+ }
80+
81+ long interval = KVMGlobalConfig .VM_HOST_FILE_SYNC_INTERVAL .value (Long .class );
5582 trackerThread = threadFacade .submitPeriodicTask (new PeriodicTask () {
5683 @ Override
5784 public TimeUnit getTimeUnit () {
@@ -60,7 +87,7 @@ public TimeUnit getTimeUnit() {
6087
6188 @ Override
6289 public long getInterval () {
63- return SYNC_INTERVAL_SECONDS ;
90+ return interval ;
6491 }
6592
6693 @ Override
@@ -74,16 +101,6 @@ public void run() {
74101 syncVmHostFiles ();
75102 }
76103 });
77-
78- return true ;
79- }
80-
81- @ Override
82- public boolean stop () {
83- if (trackerThread != null ) {
84- trackerThread .cancel (true );
85- }
86- return true ;
87104 }
88105
89106 private void syncVmHostFiles () {
@@ -104,6 +121,8 @@ private void syncVmHostFiles() {
104121 .collect (Collectors .groupingBy (f -> f .getVmInstanceUuid () + "::" + f .getHostUuid ()));
105122 List <List <VmHostFileVO >> groups = new ArrayList <>(grouped .values ());
106123
124+ int concurrency = KVMGlobalConfig .VM_HOST_FILE_SYNC_CONCURRENCY .value (Integer .class );
125+
107126 new While <>(groups ).step ((group , whileCompletion ) -> {
108127 VmHostFileVO first = group .get (0 );
109128 String vmUuid = first .getVmInstanceUuid ();
@@ -137,7 +156,7 @@ public void run(MessageReply reply) {
137156 whileCompletion .done ();
138157 }
139158 });
140- }, SYNC_CONCURRENCY ).run (new WhileDoneCompletion (null ) {
159+ }, concurrency ).run (new WhileDoneCompletion (null ) {
141160 @ Override
142161 public void done (ErrorCodeList errorCodeList ) {
143162 // periodic sync round finished, empty callback
0 commit comments