From b12254abdf64161ae24315b798e59c013a7c3b49 Mon Sep 17 00:00:00 2001 From: Ahoo Wang Date: Thu, 22 Aug 2024 11:49:44 +0800 Subject: [PATCH] feat(mongo): Remove useless `ensureIdSegment` --- .../ahoo/cosid/mongo/IdSegmentCollection.java | 3 --- .../cosid/mongo/MongoIdSegmentCollection.java | 20 ------------------ .../MongoReactiveIdSegmentCollection.java | 21 ------------------- .../mongo/MongoIdSegmentInitializerTest.java | 13 ------------ 4 files changed, 57 deletions(-) diff --git a/cosid-mongo/src/main/java/me/ahoo/cosid/mongo/IdSegmentCollection.java b/cosid-mongo/src/main/java/me/ahoo/cosid/mongo/IdSegmentCollection.java index f415e39409..20d4bc16d3 100644 --- a/cosid-mongo/src/main/java/me/ahoo/cosid/mongo/IdSegmentCollection.java +++ b/cosid-mongo/src/main/java/me/ahoo/cosid/mongo/IdSegmentCollection.java @@ -17,7 +17,4 @@ public interface IdSegmentCollection { String COLLECTION_NAME = "cosid"; long incrementAndGet(String namespacedName, long step); - - boolean ensureIdSegment(String segmentName, long offset); - } diff --git a/cosid-mongo/src/main/java/me/ahoo/cosid/mongo/MongoIdSegmentCollection.java b/cosid-mongo/src/main/java/me/ahoo/cosid/mongo/MongoIdSegmentCollection.java index 1511ad3069..d9e76a8305 100644 --- a/cosid-mongo/src/main/java/me/ahoo/cosid/mongo/MongoIdSegmentCollection.java +++ b/cosid-mongo/src/main/java/me/ahoo/cosid/mongo/MongoIdSegmentCollection.java @@ -13,11 +13,9 @@ package me.ahoo.cosid.mongo; -import static me.ahoo.cosid.mongo.IdSegmentOperates.ensureIdSegmentDocument; import static me.ahoo.cosid.mongo.IdSegmentOperates.incrementAndGetUpdates; import com.google.common.base.Preconditions; -import com.mongodb.MongoWriteException; import com.mongodb.client.MongoCollection; import com.mongodb.client.model.Filters; import lombok.extern.slf4j.Slf4j; @@ -45,22 +43,4 @@ public long incrementAndGet(String namespacedName, long step) { Long lastMaxId = afterDoc.getLong(IdSegmentOperates.LAST_MAX_ID_FIELD); return Objects.requireNonNull(lastMaxId); } - - @Deprecated - @Override - public boolean ensureIdSegment(String segmentName, long offset) { - if (log.isInfoEnabled()) { - log.info("Ensure IdSegment:[{}]", segmentName); - } - try { - Document document = ensureIdSegmentDocument(segmentName, offset); - cosidCollection.insertOne(document); - return true; - } catch (MongoWriteException mongoWriteException) { - if (log.isInfoEnabled()) { - log.info("Ensure IdSegment:[{}] Failed", segmentName, mongoWriteException); - } - return false; - } - } } diff --git a/cosid-mongo/src/main/java/me/ahoo/cosid/mongo/reactive/MongoReactiveIdSegmentCollection.java b/cosid-mongo/src/main/java/me/ahoo/cosid/mongo/reactive/MongoReactiveIdSegmentCollection.java index 127e5133c9..7d12182c83 100644 --- a/cosid-mongo/src/main/java/me/ahoo/cosid/mongo/reactive/MongoReactiveIdSegmentCollection.java +++ b/cosid-mongo/src/main/java/me/ahoo/cosid/mongo/reactive/MongoReactiveIdSegmentCollection.java @@ -13,7 +13,6 @@ package me.ahoo.cosid.mongo.reactive; -import static me.ahoo.cosid.mongo.IdSegmentOperates.ensureIdSegmentDocument; import static me.ahoo.cosid.mongo.IdSegmentOperates.incrementAndGetUpdates; import me.ahoo.cosid.mongo.Documents; @@ -21,9 +20,7 @@ import me.ahoo.cosid.mongo.IdSegmentOperates; import com.google.common.base.Preconditions; -import com.mongodb.MongoWriteException; import com.mongodb.client.model.Filters; -import com.mongodb.client.result.InsertOneResult; import com.mongodb.reactivestreams.client.MongoCollection; import lombok.extern.slf4j.Slf4j; import org.bson.Document; @@ -52,22 +49,4 @@ public long incrementAndGet(String namespacedName, long step) { Long lastMaxId = afterDoc.getLong(IdSegmentOperates.LAST_MAX_ID_FIELD); return Objects.requireNonNull(lastMaxId); } - - @Override - public boolean ensureIdSegment(String segmentName, long offset) { - if (log.isInfoEnabled()) { - log.info("Ensure IdSegment:[{}]", segmentName); - } - try { - Document document = ensureIdSegmentDocument(segmentName, offset); - Publisher publisher = cosidCollection.insertOne(document); - BlockingAdapter.block(publisher); - return true; - } catch (MongoWriteException mongoWriteException) { - if (log.isInfoEnabled()) { - log.info("Ensure IdSegment:[{}] Failed:[{}]", segmentName, mongoWriteException.getMessage()); - } - return false; - } - } } diff --git a/cosid-mongo/src/test/java/me/ahoo/cosid/mongo/MongoIdSegmentInitializerTest.java b/cosid-mongo/src/test/java/me/ahoo/cosid/mongo/MongoIdSegmentInitializerTest.java index bfdd6df322..6d0816f667 100644 --- a/cosid-mongo/src/test/java/me/ahoo/cosid/mongo/MongoIdSegmentInitializerTest.java +++ b/cosid-mongo/src/test/java/me/ahoo/cosid/mongo/MongoIdSegmentInitializerTest.java @@ -13,14 +13,10 @@ package me.ahoo.cosid.mongo; -import static org.hamcrest.MatcherAssert.assertThat; - -import me.ahoo.cosid.test.MockIdGenerator; import me.ahoo.cosid.test.container.MongoLauncher; import com.mongodb.client.MongoClients; import com.mongodb.client.MongoDatabase; -import org.hamcrest.Matchers; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; @@ -40,13 +36,4 @@ void setup() { void ensureCosIdCollection() { idSegmentInitializer.ensureCosIdCollection(); } - - @Test - void ensureIdSegment() { - String namespace = MockIdGenerator.INSTANCE.generateAsString(); - boolean actual = cosIdSegmentCollection.ensureIdSegment(namespace, 0); - assertThat(actual, Matchers.equalTo(true)); - actual = cosIdSegmentCollection.ensureIdSegment(namespace, 0); - assertThat(actual, Matchers.equalTo(false)); - } } \ No newline at end of file