This repository has been archived by the owner on Nov 14, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 15
Simplify getCandidateCellsForSweeping() #2439
Merged
gbonik
merged 2 commits into
feature/sweep-rewrite
from
feature/simplify-get-candidates
Oct 10, 2017
Merged
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -16,113 +16,18 @@ | |
|
||
package com.palantir.atlasdb.keyvalue.dbkvs.impl.postgres; | ||
|
||
import static org.junit.Assert.assertEquals; | ||
|
||
import java.util.List; | ||
|
||
import org.junit.Test; | ||
|
||
import com.google.common.collect.ImmutableList; | ||
import com.google.common.collect.Iterators; | ||
import com.palantir.atlasdb.encoding.PtBytes; | ||
import com.palantir.atlasdb.keyvalue.api.CandidateCellForSweeping; | ||
import com.palantir.atlasdb.keyvalue.api.CandidateCellForSweepingRequest; | ||
import com.palantir.atlasdb.keyvalue.api.ImmutableCandidateCellForSweeping; | ||
import com.palantir.atlasdb.keyvalue.api.KeyValueService; | ||
import com.palantir.atlasdb.keyvalue.dbkvs.DbKeyValueServiceConfig; | ||
import com.palantir.atlasdb.keyvalue.dbkvs.DbkvsPostgresTestSuite; | ||
import com.palantir.atlasdb.keyvalue.dbkvs.impl.ConnectionManagerAwareDbKvs; | ||
import com.palantir.atlasdb.keyvalue.dbkvs.impl.SqlConnectionSupplier; | ||
import com.palantir.atlasdb.keyvalue.dbkvs.impl.sweep.DbKvsGetCandidateCellsForSweeping; | ||
import com.palantir.atlasdb.keyvalue.impl.AbstractGetCandidateCellsForSweepingTest; | ||
import com.palantir.common.base.ClosableIterator; | ||
|
||
public class DbKvsPostgresGetCandidateCellsForSweepingTest extends AbstractGetCandidateCellsForSweepingTest { | ||
|
||
private static DbKeyValueServiceConfig config; | ||
private static SqlConnectionSupplier connectionSupplier; | ||
|
||
@Override | ||
protected KeyValueService createKeyValueService() { | ||
config = DbkvsPostgresTestSuite.getKvsConfig(); | ||
ConnectionManagerAwareDbKvs kvs = ConnectionManagerAwareDbKvs.create(config); | ||
connectionSupplier = kvs.getSqlConnectionSupplier(); | ||
return kvs; | ||
} | ||
|
||
@Test | ||
public void singleCellSpanningSeveralPages() { | ||
new TestDataBuilder() | ||
.put(10, 1, 1000) | ||
.put(10, 1, 1001) | ||
.put(10, 1, 1002) | ||
.put(10, 1, 1003) | ||
.put(10, 1, 1004) | ||
.store(); | ||
List<CandidateCellForSweeping> cells = getWithOverriddenLimit( | ||
conservativeRequest(PtBytes.EMPTY_BYTE_ARRAY, 2000L, Long.MIN_VALUE), 2); | ||
assertEquals(ImmutableList.of(ImmutableCandidateCellForSweeping.builder() | ||
.cell(cell(10, 1)) | ||
.isLatestValueEmpty(false) | ||
.numCellsTsPairsExamined(5) | ||
.sortedTimestamps(1000L, 1001L, 1002L, 1003L, 1004L) | ||
.build()), cells); | ||
} | ||
|
||
@Test | ||
public void returnFirstAndLastCellOfThePage() { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This test still seems valuable, why did we get rid of this? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This tested implementation-specific behavior that doesn't exist anymore |
||
new TestDataBuilder() | ||
.put(10, 1, 1000) | ||
.put(10, 2, 400) | ||
// The cell (20, 1) is not a candidate because the minimumUncommittedTimestamp is 750, which is greater | ||
// than 500. However, we still need to return this cell since it's at the page boundary. | ||
.put(20, 1, 500) | ||
// <---- page boundary here ----> | ||
// Again, this cell is not a candidate, but we need to return it | ||
// since it's the first SQL row in the page. | ||
.put(30, 1, 600) | ||
.store(); | ||
List<CandidateCellForSweeping> cells = getWithOverriddenLimit( | ||
conservativeRequest(PtBytes.EMPTY_BYTE_ARRAY, 2000L, 750L), 3); | ||
assertEquals( | ||
ImmutableList.of( | ||
ImmutableCandidateCellForSweeping.builder() | ||
.cell(cell(10, 1)) | ||
.isLatestValueEmpty(false) | ||
.numCellsTsPairsExamined(1) | ||
.sortedTimestamps(1000L) | ||
.build(), | ||
ImmutableCandidateCellForSweeping.builder() | ||
.cell(cell(20, 1)) | ||
.isLatestValueEmpty(false) | ||
.numCellsTsPairsExamined(3) | ||
// No timestamps because the cell is not a real candidate | ||
.sortedTimestamps() | ||
.build(), | ||
ImmutableCandidateCellForSweeping.builder() | ||
.cell(cell(30, 1)) | ||
.isLatestValueEmpty(false) | ||
.numCellsTsPairsExamined(4) | ||
// No timestamps because the cell is not a real candidate | ||
.sortedTimestamps() | ||
.build()), | ||
cells); | ||
} | ||
|
||
private List<CandidateCellForSweeping> getWithOverriddenLimit( | ||
CandidateCellForSweepingRequest request, | ||
int sqlRowLimitOverride) { | ||
try (ClosableIterator<List<CandidateCellForSweeping>> iter = createImpl(sqlRowLimitOverride) | ||
.getCandidateCellsForSweeping(TEST_TABLE, request, null)) { | ||
return ImmutableList.copyOf(Iterators.concat(Iterators.transform(iter, List::iterator))); | ||
} | ||
} | ||
|
||
private DbKvsGetCandidateCellsForSweeping createImpl(int sqlRowLimitOverride) { | ||
return new PostgresGetCandidateCellsForSweeping( | ||
new PostgresPrefixedTableNames(config.ddl()), | ||
connectionSupplier, | ||
x -> sqlRowLimitOverride); | ||
DbKeyValueServiceConfig config = DbkvsPostgresTestSuite.getKvsConfig(); | ||
return ConnectionManagerAwareDbKvs.create(config); | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I had to check if we should still be returning
EMPTY_LONG_ARRAY
if there is just one timestamp - I see that case excluded atSweepableCellFilter.getCellToSweep
, so looks ok to me.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Even if there is one timestamp, you still might need to sweep it (if that timestamp is uncommitted)