|
41 | 41 | import org.elasticsearch.common.io.FileSystemUtils; |
42 | 42 | import org.elasticsearch.common.io.stream.BytesStreamOutput; |
43 | 43 | import org.elasticsearch.common.io.stream.StreamInput; |
| 44 | +import org.elasticsearch.common.lease.Releasable; |
44 | 45 | import org.elasticsearch.common.settings.Settings; |
45 | 46 | import org.elasticsearch.common.unit.ByteSizeUnit; |
46 | 47 | import org.elasticsearch.common.unit.ByteSizeValue; |
|
102 | 103 | import java.util.stream.Collectors; |
103 | 104 |
|
104 | 105 | import static org.elasticsearch.common.util.BigArrays.NON_RECYCLING_INSTANCE; |
| 106 | +import static org.elasticsearch.common.util.BigArrays.PAGE_SIZE_IN_BYTES; |
105 | 107 | import static org.hamcrest.Matchers.containsString; |
106 | 108 | import static org.hamcrest.Matchers.equalTo; |
107 | 109 | import static org.hamcrest.Matchers.greaterThan; |
@@ -2153,34 +2155,59 @@ public void testRollGenerationBetweenPrepareCommitAndCommit() throws IOException |
2153 | 2155 | final long generation = translog.currentFileGeneration(); |
2154 | 2156 | int seqNo = 0; |
2155 | 2157 |
|
2156 | | - final int operationsBefore = randomIntBetween(1, 256); |
2157 | | - for (int i = 0; i < operationsBefore; i++) { |
2158 | | - translog.add(new Translog.NoOp(seqNo++, 0, "test")); |
| 2158 | + final int rollsBefore = randomIntBetween(0, 16); |
| 2159 | + for (int r = 1; r <= rollsBefore; r++) { |
| 2160 | + final int operationsBefore = randomIntBetween(1, 256); |
| 2161 | + for (int i = 0; i < operationsBefore; i++) { |
| 2162 | + translog.add(new Translog.NoOp(seqNo++, 0, "test")); |
| 2163 | + } |
| 2164 | + |
| 2165 | + try (Releasable ignored = translog.writeLock.acquire()) { |
| 2166 | + translog.rollGeneration(); |
| 2167 | + } |
| 2168 | + |
| 2169 | + assertThat(translog.currentFileGeneration(), equalTo(generation + r)); |
| 2170 | + for (int i = 0; i <= r; i++) { |
| 2171 | + assertFileIsPresent(translog, generation + r); |
| 2172 | + } |
2159 | 2173 | } |
2160 | 2174 |
|
| 2175 | + assertThat(translog.currentFileGeneration(), equalTo(generation + rollsBefore)); |
2161 | 2176 | translog.prepareCommit(); |
2162 | | - assertThat(translog.currentFileGeneration(), equalTo(generation + 1)); |
2163 | | - assertFileIsPresent(translog, generation); |
2164 | | - assertFileIsPresent(translog, generation + 1); |
| 2177 | + assertThat(translog.currentFileGeneration(), equalTo(generation + rollsBefore + 1)); |
2165 | 2178 |
|
2166 | | - final int operationsBetween = randomIntBetween(1, 256); |
2167 | | - for (int i = 0; i < operationsBetween; i++) { |
2168 | | - translog.add(new Translog.NoOp(seqNo++, 0, "test")); |
| 2179 | + for (int i = 0; i <= rollsBefore + 1; i++) { |
| 2180 | + assertFileIsPresent(translog, generation + i); |
2169 | 2181 | } |
2170 | 2182 |
|
2171 | | - try (ReleasableLock ignored = translog.writeLock.acquire()) { |
2172 | | - translog.rollGeneration(); |
| 2183 | + final int rollsBetween = randomIntBetween(0, 16); |
| 2184 | + for (int r = 1; r <= rollsBetween; r++) { |
| 2185 | + final int operationsBetween = randomIntBetween(1, 256); |
| 2186 | + for (int i = 0; i < operationsBetween; i++) { |
| 2187 | + translog.add(new Translog.NoOp(seqNo++, 0, "test")); |
| 2188 | + } |
| 2189 | + |
| 2190 | + try (Releasable ignored = translog.writeLock.acquire()) { |
| 2191 | + translog.rollGeneration(); |
| 2192 | + } |
| 2193 | + |
| 2194 | + assertThat( |
| 2195 | + translog.currentFileGeneration(), |
| 2196 | + equalTo(generation + rollsBefore + 1 + r)); |
| 2197 | + for (int i = 0; i <= rollsBefore + 1 + r; i++) { |
| 2198 | + assertFileIsPresent(translog, generation + i); |
| 2199 | + } |
2173 | 2200 | } |
2174 | | - assertThat(translog.currentFileGeneration(), equalTo(generation + 2)); |
2175 | | - assertFileIsPresent(translog, generation); |
2176 | | - assertFileIsPresent(translog, generation + 1); |
2177 | | - assertFileIsPresent(translog, generation + 2); |
2178 | 2201 |
|
2179 | 2202 | translog.commit(); |
2180 | 2203 |
|
2181 | | - assertFileDeleted(translog, generation); |
2182 | | - assertFileDeleted(translog, generation + 1); |
2183 | | - assertFileIsPresent(translog, generation + 2); |
| 2204 | + for (int i = 0; i < rollsBefore; i++) { |
| 2205 | + assertFileDeleted(translog, generation + i); |
| 2206 | + } |
| 2207 | + for (int i = rollsBefore; i <= rollsBefore + 1 + rollsBetween; i++) { |
| 2208 | + assertFileIsPresent(translog, generation + i); |
| 2209 | + } |
| 2210 | + |
2184 | 2211 | } |
2185 | 2212 |
|
2186 | 2213 | } |
0 commit comments