File tree Expand file tree Collapse file tree 2 files changed +39
-0
lines changed
main/java/org/apache/rocketmq/store/timer
test/java/org/apache/rocketmq/store/timer Expand file tree Collapse file tree 2 files changed +39
-0
lines changed Original file line number Diff line number Diff line change @@ -1344,6 +1344,9 @@ public void checkAndReviseMetrics() {
13441344 bf .getInt ();//size
13451345 bf .getLong ();//prev pos
13461346 int magic = bf .getInt (); //magic
1347+ if (magic == TimerLog .BLANK_MAGIC_CODE ) {
1348+ break ;
1349+ }
13471350 long enqueueTime = bf .getLong ();
13481351 long delayedTime = bf .getInt () + enqueueTime ;
13491352 long offsetPy = bf .getLong ();
Original file line number Diff line number Diff line change @@ -97,6 +97,42 @@ public void testRecovery() throws Exception {
9797 assertArrayEquals (expect , data );
9898 }
9999
100+ @ Test
101+ public void testAppendBlankByteBuffer () throws Exception {
102+ TimerLog timerLog = createTimerLog (null );
103+ ByteBuffer byteBuffer = ByteBuffer .allocate (TimerLog .UNIT_SIZE );
104+ byteBuffer .putInt (TimerLog .UNIT_SIZE );
105+ byteBuffer .putLong (Long .MAX_VALUE );
106+ byteBuffer .putInt (0 );
107+ byteBuffer .putLong (Long .MAX_VALUE );
108+ byteBuffer .putInt (0 );
109+ byteBuffer .putLong (1000 );
110+ byteBuffer .putInt (10 );
111+ byteBuffer .putInt (123 );
112+ byteBuffer .putInt (0 );
113+ int maxAppend = 1024 / TimerLog .UNIT_SIZE + 1 ;
114+ for (int i = 0 ; i < maxAppend ; i ++) {
115+ timerLog .append (byteBuffer .array (), 0 , TimerLog .UNIT_SIZE );
116+ }
117+ SelectMappedBufferResult sbr = timerLog .getWholeBuffer (0 );
118+ ByteBuffer bf = sbr .getByteBuffer ();
119+ for (int position = 0 ; position < sbr .getSize (); position += TimerLog .UNIT_SIZE ) {
120+ bf .position (position );
121+ bf .getInt ();
122+ bf .getLong ();
123+ int magic = bf .getInt ();
124+ if (position / TimerLog .UNIT_SIZE == maxAppend - 1 ) {
125+ assertEquals (TimerLog .BLANK_MAGIC_CODE , magic );
126+ continue ;
127+ }
128+ bf .getLong ();
129+ bf .getInt ();
130+ bf .getLong ();
131+ bf .getInt ();
132+ bf .getInt ();
133+ }
134+ }
135+
100136 @ After
101137 public void shutdown () {
102138 for (TimerLog timerLog : timerLogs ) {
You can’t perform that action at this time.
0 commit comments