Skip to content

Commit 727dc0a

Browse files
committed
adjust removeBefore logic in big array
1 parent 8c9a61a commit 727dc0a

4 files changed

Lines changed: 19 additions & 23 deletions

File tree

src/main/java/com/leansoft/bigqueue/BigArrayImpl.java

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -227,13 +227,13 @@ public void removeBefore(long timestamp) throws IOException {
227227
arrayWriteLock.lock();
228228
long firstIndexPageIndex = this.indexPageFactory.getFirstPageIndexBefore(timestamp);
229229
if (firstIndexPageIndex >= 0) {
230-
long nextIndexPageIndex = firstIndexPageIndex;
231-
if (nextIndexPageIndex == Long.MAX_VALUE) { //wrap
232-
nextIndexPageIndex = 0L;
233-
} else {
234-
nextIndexPageIndex++;
235-
}
236-
long toRemoveBeforeIndex = Calculator.mul(nextIndexPageIndex, INDEX_ITEMS_PER_PAGE_BITS);
230+
// long nextIndexPageIndex = firstIndexPageIndex;
231+
// if (nextIndexPageIndex == Long.MAX_VALUE) { //wrap
232+
// nextIndexPageIndex = 0L;
233+
// } else {
234+
// nextIndexPageIndex++;
235+
// }
236+
long toRemoveBeforeIndex = Calculator.mul(firstIndexPageIndex, INDEX_ITEMS_PER_PAGE_BITS);
237237
removeBeforeIndex(toRemoveBeforeIndex);
238238
}
239239
} catch (IndexOutOfBoundsException ex) {

src/main/java/com/leansoft/bigqueue/page/MappedPageFactoryImpl.java

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -186,9 +186,7 @@ public void deletePage(long index) throws IOException {
186186
}
187187
}
188188
if (deleted) {
189-
if (logger.isDebugEnabled()) {
190-
logger.debug("Page file " + fileName + " was just deleted.");
191-
}
189+
logger.info("Page file " + fileName + " was just deleted.");
192190
} else {
193191
logger.warn("fail to delete file " + fileName + " after max " + maxRound + " rounds of try, you may delete it manually.");
194192
}

src/test/java/com/leansoft/bigqueue/FanOutQueueTest.java

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -225,7 +225,15 @@ public void removeBeforeTest() throws IOException {
225225

226226
foQueue.removeBefore(timestamp);
227227

228-
assertTrue(foQueue.size(fid) == 1024 * 1024);
228+
timestamp = System.currentTimeMillis();
229+
String randomString3 = TestUtil.randomString(32);
230+
for(int i = 0; i < 1024 * 1024; i++) {
231+
foQueue.enqueue(randomString3.getBytes());
232+
}
233+
234+
foQueue.removeBefore(timestamp);
235+
236+
assertTrue(foQueue.size(fid) == 2 * 1024 * 1024);
229237
assertEquals(randomString2, new String(foQueue.peek(fid)));
230238
}
231239

src/test/resources/log4j.properties

Lines changed: 2 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -12,18 +12,8 @@
1212
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
1313
# See the License for the specific language governing permissions and
1414
# limitations under the License.
15-
log4j.rootLogger=INFO,stdout
15+
log4j.rootLogger=WARN,stdout
1616

1717
log4j.appender.stdout=org.apache.log4j.ConsoleAppender
1818
log4j.appender.stdout.layout=org.apache.log4j.PatternLayout
19-
log4j.appender.stdout.layout.ConversionPattern=[%d] %p %m (%C.java:%L)%n
20-
21-
#log4j.logger.bigqueue.request.logger=DEBUG
22-
log4j.logger.org.apache.zookeeper=WARN
23-
log4j.logger.com.github.zkclient=WARN
24-
#log4j.logger.com.leansoft.bigqueue.producer=DEBUG
25-
#log4j.logger.com.leansoft.bigqueue.log.Log=DEBUG
26-
#log4j.logger.com.leansoft.bigqueue=DEBUG
27-
#log4j.logger.com.leansoft.bigqueue.log=DEBUG
28-
#log4j.logger.com.leansoft.bigqueue.consumer.ZookeeperConsumerConnector=DEBUG
29-
#log4j.logger.com.leansoft.bigqueue.producer.ProducerPool=DEBUG
19+
log4j.appender.stdout.layout.ConversionPattern=[%d] %p %m (%C.java:%L)%n

0 commit comments

Comments
 (0)