Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Stop workers when the manager is stopped, display warning if a new da… #66

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions src/main/java/com/gravity9/mongocse/ConfigManager.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import com.mongodb.client.model.Filters;
import com.mongodb.client.model.Updates;

import java.util.ArrayList;
import java.util.List;
import java.util.Optional;
import org.bson.types.ObjectId;
Expand All @@ -21,6 +22,10 @@ class ConfigManager {

ConfigManager(MongoConfig mongoConfig, MongoClientProvider clientProvider) {
MongoDatabase db = clientProvider.getClient().getDatabase(mongoConfig.getDatabaseName());
ArrayList<String> dbList = clientProvider.getClient().listDatabaseNames().into(new ArrayList<>());
if (!dbList.contains(mongoConfig.getDatabaseName())) {
log.warn("Database: {} does not exist. A new DB will be created.", mongoConfig.getDatabaseName());
}
workerConfigCollection = db.getCollection(mongoConfig.getWorkerConfigCollectionName(), ChangeStreamWorkerConfig.class);
clusterConfigCollection = db.getCollection(mongoConfig.getClusterConfigCollectionName(), WorkerClusterConfig.class);
}
Expand Down
1 change: 1 addition & 0 deletions src/main/java/com/gravity9/mongocse/MongoCseManager.java
Original file line number Diff line number Diff line change
Expand Up @@ -140,6 +140,7 @@ private void runInNewThread(MongoChangeStreamWorker worker) {

@Override
public void close() throws IOException {
stop();
clientProvider.close();
}
}