-
Notifications
You must be signed in to change notification settings - Fork 454
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Verify checkpoint files are completely written out when checking if they exist #1086
Changes from 9 commits
4db1858
c06bc29
bad979a
d244413
8af3969
58ab6ec
4094224
d1048d8
86fa49b
0f82f3a
b47f7b0
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -282,33 +282,68 @@ func TestTimeAndVolumeIndexFromFileSetFilename(t *testing.T) { | |
} | ||
|
||
func TestFileExists(t *testing.T) { | ||
dir := createTempDir(t) | ||
defer os.RemoveAll(dir) | ||
|
||
shard := uint32(10) | ||
start := time.Now() | ||
shardDir := ShardDataDirPath(dir, testNs1ID, shard) | ||
err := os.MkdirAll(shardDir, defaultNewDirectoryMode) | ||
var ( | ||
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. mind making a new test which only tests the 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. Added a test and put a comment in the function itself |
||
dir = createTempDir(t) | ||
shard = uint32(10) | ||
start = time.Now() | ||
shardDir = ShardDataDirPath(dir, testNs1ID, shard) | ||
checkpointFileBuf = make([]byte, CheckpointFileSizeBytes) | ||
err = os.MkdirAll(shardDir, defaultNewDirectoryMode) | ||
) | ||
defer os.RemoveAll(dir) | ||
require.NoError(t, err) | ||
|
||
infoFilePath := filesetPathFromTime(shardDir, start, infoFileSuffix) | ||
createDataFile(t, shardDir, start, infoFileSuffix, nil) | ||
createDataFile(t, shardDir, start, infoFileSuffix, checkpointFileBuf) | ||
require.True(t, mustFileExists(t, infoFilePath)) | ||
exists, err := DataFileSetExistsAt(dir, testNs1ID, uint32(shard), start) | ||
require.NoError(t, err) | ||
require.False(t, exists) | ||
|
||
checkpointFilePath := filesetPathFromTime(shardDir, start, checkpointFileSuffix) | ||
createDataFile(t, shardDir, start, checkpointFileSuffix, nil) | ||
require.True(t, mustFileExists(t, checkpointFilePath)) | ||
createDataFile(t, shardDir, start, checkpointFileSuffix, checkpointFileBuf) | ||
exists, err = DataFileSetExistsAt(dir, testNs1ID, uint32(shard), start) | ||
require.NoError(t, err) | ||
require.True(t, exists) | ||
|
||
exists, err = CompleteCheckpointFileExists(checkpointFilePath) | ||
require.NoError(t, err) | ||
require.True(t, exists) | ||
|
||
_, err = FileExists(checkpointFilePath) | ||
require.Error(t, err) | ||
|
||
os.Remove(infoFilePath) | ||
require.False(t, mustFileExists(t, infoFilePath)) | ||
} | ||
|
||
func TestCompleteCheckpointFileExists(t *testing.T) { | ||
var ( | ||
dir = createTempDir(t) | ||
shard = uint32(10) | ||
start = time.Now() | ||
shardDir = ShardDataDirPath(dir, testNs1ID, shard) | ||
checkpointFilePath = filesetPathFromTime(shardDir, start, checkpointFileSuffix) | ||
err = os.MkdirAll(shardDir, defaultNewDirectoryMode) | ||
|
||
validCheckpointFileBuf = make([]byte, CheckpointFileSizeBytes) | ||
invalidCheckpointFileBuf = make([]byte, CheckpointFileSizeBytes+1) | ||
) | ||
defer os.RemoveAll(dir) | ||
require.NoError(t, err) | ||
|
||
createDataFile(t, shardDir, start, checkpointFileSuffix, invalidCheckpointFileBuf) | ||
exists, err := CompleteCheckpointFileExists(checkpointFilePath) | ||
require.NoError(t, err) | ||
require.False(t, exists) | ||
|
||
createDataFile(t, shardDir, start, checkpointFileSuffix, validCheckpointFileBuf) | ||
exists, err = CompleteCheckpointFileExists(checkpointFilePath) | ||
require.NoError(t, err) | ||
require.True(t, exists) | ||
} | ||
|
||
func TestShardDirPath(t *testing.T) { | ||
require.Equal(t, "foo/bar/data/testNs/12", ShardDataDirPath("foo/bar", testNs1ID, 12)) | ||
require.Equal(t, "foo/bar/data/testNs/12", ShardDataDirPath("foo/bar/", testNs1ID, 12)) | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -253,6 +253,12 @@ func TestSimpleReadWrite(t *testing.T) { | |
readTestData(t, r, 0, testWriterStart, entries) | ||
} | ||
|
||
func TestCheckpointFileSizeBytesSize(t *testing.T) { | ||
// These values need to match so that the logic for determining whether | ||
// a checkpoint file is complete or not remains correct. | ||
require.Equal(t, digest.DigestLenBytes, CheckpointFileSizeBytes) | ||
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. Instead of this, why don't you just make 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. Yeah I discussed this with Prateek and we like the idea that the tests would break if you changed one and not the other just to make the person think about the change more |
||
} | ||
|
||
func TestDuplicateWrite(t *testing.T) { | ||
dir := createTempDir(t) | ||
filePathPrefix := filepath.Join(dir, "") | ||
|
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.
should this have the same
strings.Contains
check?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.
what would the check be? This one is specifically written to be used for checkpoint files, and if its not a checkpoint file you'll probably get an error anyways because its unlikely the file you're checking is exactly 4 bytes
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 think prateek just means, should you check that the filepath they're checking for definitely is a checkpoint file (i.e. make sure that it passes the checkpoint suffix)? I think that makes sense.
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.
Ah ok, I guess I just wasn't worried about it because this function is harder to misuse but I'll add it
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.
done