You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@streampipes.apache.org by ri...@apache.org on 2022/11/29 09:49:01 UTC
[streampipes] branch dev updated: [hotfix] Avoid document conflicts when handling adapter registration
This is an automated email from the ASF dual-hosted git repository.
riemer pushed a commit to branch dev
in repository https://gitbox.apache.org/repos/asf/streampipes.git
The following commit(s) were added to refs/heads/dev by this push:
new 3929afc24 [hotfix] Avoid document conflicts when handling adapter registration
3929afc24 is described below
commit 3929afc24ec73f6cfc020700facbc31392ce3d94
Author: Dominik Riemer <do...@gmail.com>
AuthorDate: Tue Nov 29 10:48:51 2022 +0100
[hotfix] Avoid document conflicts when handling adapter registration
---
.../master/health/AdapterHealthCheck.java | 1 -
.../master/health/AdapterOperationLock.java | 37 ++++++++++++++++++++++
.../management/WorkerAdministrationManagement.java | 34 +++++++++++++++++---
3 files changed, 67 insertions(+), 5 deletions(-)
diff --git a/streampipes-connect-container-master/src/main/java/org/apache/streampipes/connect/container/master/health/AdapterHealthCheck.java b/streampipes-connect-container-master/src/main/java/org/apache/streampipes/connect/container/master/health/AdapterHealthCheck.java
index 689978fde..1704c84ce 100644
--- a/streampipes-connect-container-master/src/main/java/org/apache/streampipes/connect/container/master/health/AdapterHealthCheck.java
+++ b/streampipes-connect-container-master/src/main/java/org/apache/streampipes/connect/container/master/health/AdapterHealthCheck.java
@@ -13,7 +13,6 @@
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
- *
*/
package org.apache.streampipes.connect.container.master.health;
diff --git a/streampipes-connect-container-master/src/main/java/org/apache/streampipes/connect/container/master/health/AdapterOperationLock.java b/streampipes-connect-container-master/src/main/java/org/apache/streampipes/connect/container/master/health/AdapterOperationLock.java
new file mode 100644
index 000000000..38fdd0c5a
--- /dev/null
+++ b/streampipes-connect-container-master/src/main/java/org/apache/streampipes/connect/container/master/health/AdapterOperationLock.java
@@ -0,0 +1,37 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.streampipes.connect.container.master.health;
+
+public enum AdapterOperationLock {
+
+ INSTANCE;
+
+ private boolean locked;
+
+ public void lock() {
+ this.locked = true;
+ }
+
+ public void unlock() {
+ this.locked = false;
+ }
+
+ public boolean isLocked() {
+ return locked;
+ }
+}
diff --git a/streampipes-connect-container-master/src/main/java/org/apache/streampipes/connect/container/master/management/WorkerAdministrationManagement.java b/streampipes-connect-container-master/src/main/java/org/apache/streampipes/connect/container/master/management/WorkerAdministrationManagement.java
index 11249295d..c66aef2df 100644
--- a/streampipes-connect-container-master/src/main/java/org/apache/streampipes/connect/container/master/management/WorkerAdministrationManagement.java
+++ b/streampipes-connect-container-master/src/main/java/org/apache/streampipes/connect/container/master/management/WorkerAdministrationManagement.java
@@ -19,6 +19,7 @@
package org.apache.streampipes.connect.container.master.management;
import org.apache.streampipes.connect.container.master.health.AdapterHealthCheck;
+import org.apache.streampipes.connect.container.master.health.AdapterOperationLock;
import org.apache.streampipes.model.connect.adapter.AdapterDescription;
import org.apache.streampipes.storage.api.IAdapterStorage;
import org.apache.streampipes.storage.couchdb.CouchDbStorageManager;
@@ -26,14 +27,16 @@ import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import java.util.List;
+import java.util.concurrent.TimeUnit;
public class WorkerAdministrationManagement {
private static final Logger LOG = LoggerFactory.getLogger(AdapterMasterManagement.class);
+ private static final int MAX_RETRIES = 3;
- private IAdapterStorage adapterDescriptionStorage;
+ private final IAdapterStorage adapterDescriptionStorage;
- private AdapterHealthCheck adapterHealthCheck;
+ private final AdapterHealthCheck adapterHealthCheck;
public WorkerAdministrationManagement() {
this.adapterHealthCheck = new AdapterHealthCheck();
@@ -41,7 +44,6 @@ public class WorkerAdministrationManagement {
}
public void register(List<AdapterDescription> availableAdapterDescription) {
-
List<AdapterDescription> alreadyRegisteredAdapters = this.adapterDescriptionStorage.getAllAdapters();
availableAdapterDescription.forEach(adapterDescription -> {
@@ -55,6 +57,30 @@ public class WorkerAdministrationManagement {
}
});
- this.adapterHealthCheck.checkAndRestoreAdapters();
+ int retryCount = 0;
+ checkAndRestore(retryCount);
+ }
+
+ private void checkAndRestore(int retryCount) {
+ if (AdapterOperationLock.INSTANCE.isLocked()) {
+ LOG.info("Adapter operation already in progress, {}/{}", (retryCount + 1), MAX_RETRIES);
+ if (retryCount < MAX_RETRIES) {
+ try {
+ TimeUnit.MILLISECONDS.sleep(1000);
+ retryCount++;
+ checkAndRestore(retryCount);
+ } catch (InterruptedException e) {
+ e.printStackTrace();
+ }
+ } else {
+ LOG.info("Max retries for running adapter operations reached, will do unlock which might cause conflicts...");
+ AdapterOperationLock.INSTANCE.unlock();
+ this.adapterHealthCheck.checkAndRestoreAdapters();
+ }
+ } else {
+ AdapterOperationLock.INSTANCE.lock();
+ this.adapterHealthCheck.checkAndRestoreAdapters();
+ AdapterOperationLock.INSTANCE.unlock();
+ }
}
}