-
Notifications
You must be signed in to change notification settings - Fork 179
clean up after running repair tests #372
clean up after running repair tests #372
Conversation
Yeah I noticed that too, but I think the problem is with the test itself. It should revert the state after completing. Otherwise it doesn't allow running it twice and confuses git as well I also prefer to use |
d1c1efa
to
7008fe2
Compare
@krasi-georgiev updated so that we're cleaning up after the repair tests, reverted the gitignore changes. It's a bit ugly atm but I need to sleep. I'll clean it up it in the morning. |
thanks , ping me when ready and I will review again. |
7008fe2
to
d9a2be9
Compare
@krasi-georgiev ping :) |
I just had a look at the test I did for another PR and here is a lot easyer way to achieve the same:
|
@krasi-georgiev yeah I tried that initially, we need tombstones in order to create a snapshot. I don't we want to deal with generating tombstones for this test. |
even if you need to put an empty tombstones file it would be a much cleaner solution without requiring so many lines of additional code. |
if all we needed was an empty tombstones file I would have just done that :) let me have another look |
@krasi-georgiev we can't use snapshot here anyways, it's the call to |
I made it work using:
I think we would need to do this quite often form now on so why don't we make some more generic func which takes filepaths as a param and recursively makes hard links using Something like:
than we can have: if you don't have time for the extra effort let me know and I can take over. |
Thanks @krasi-georgiev, I got it working via the block snapshotting. Unfortunately I don't understand this generic copy files helper, how do hardlinks help us here? |
look at the snapshot implementation it uses hard links instead of copying files. |
hardlinks is essentially like copying , but without even opening the files. |
Right, but it's linked to the same underlying data on disk. So modifying the file at the hardlink name modifies the file at the original name, because they're essentially the same file. Looking at the snapshot code, I don't understand how using the hardlinks gets us a copy of the DB files that we can modify without making modifications to the originals. |
Okay I see what's happening, we wanted to not modify the index and meta files so that the test could be rerun without modifying the existing db files. Snapshot creates hardlinks, but open calls functions to repair the index file and fix the meta file in temporary files, and then calls So if you want we can add a help function to do the hardlinks, but I think the name |
|
ooh yeah I misunderstood the hard-links a bit. |
@krasi-georgiev okay, done. If it's 👍 I will squash my commits. |
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 was the blocker to use something like
CopyFiles(fileutil.ReadDir(srcDir),destDir)
func CopyFiles( files ...string, destDir string)
repair_test.go
Outdated
|
||
"github.com/prometheus/tsdb/index" | ||
"github.com/prometheus/tsdb/labels" | ||
) | ||
|
||
func copyFiles(tmpIndex, tmpMeta *os.File, dir string) error { |
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.
don't need this anymore.
If |
something like this should do the trick. Than I will try if it will work for my usecase as well. |
@krasi-georgiev imo it's easier if |
I would say lets create dirs regardless of whether they will include any files. |
for |
fileutil/fileutil.go
Outdated
} | ||
|
||
// ReadDirs returns a slice of the full path to all files, including empty directories, in src dir and it's sub directories. | ||
func ReadDirs(src string) ([]string, error) { |
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 be able to simplify this using filepath.Walk
and than reuse fileutil.ReadDir()
fileutil/fileutil.go
Outdated
return err | ||
} | ||
return nil | ||
} |
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.
why not something more simple like:
data, err := ioutil.ReadFile(src)
if err != nil {
return err
}
err = ioutil.WriteFile(dst, data, 0644)
if err != nil {
return err
}
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.
we seem to use os.Rename() everywhere else so I stuck with that
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 don't see a problem here without rename.
see the latest commit, we also needed to grab extra portions of the path for files we're creating copies of so that the end up in the right destination location |
fileutil/fileutil.go
Outdated
return err | ||
} | ||
return nil | ||
} |
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 don't see a problem here without rename.
fileutil/fileutil.go
Outdated
return chunks[1] | ||
} | ||
|
||
func copyFile(dest, src string) error { |
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.
Usually the order is src, dst
this looks hacky, can you try to simplify. |
yes |
@krasi-georgiev simplified a bit. We still need a way to remove a prefix from the files we find when using |
can you also try the simplified version I suggested for |
@krasi-georgiev yep, just slipped my mind earlier. Want me to squash commits now? |
no need I will squash when I merge it. moved few bits around and updated few comment.
|
👍 changes lgtm, pushed them |
resolve the conflict and LGTM |
Signed-off-by: Callum Stytan <[email protected]>
Signed-off-by: Callum Stytan <[email protected]>
Signed-off-by: Callum Stytan <[email protected]>
directories Signed-off-by: Callum Stytan <[email protected]>
subdirectories properly Signed-off-by: Callum Stytan <[email protected]>
Signed-off-by: Callum Stytan <[email protected]>
since we don't care about this being atomic Signed-off-by: Callum Stytan <[email protected]>
Signed-off-by: Callum Stytan <[email protected]>
54c05b2
to
1337f23
Compare
done :) thanks for all the reviews @krasi-georgiev |
Thanks for spending the time on this. |
I noticed that some files are changed and others are created when running tsdb tests
Signed-off-by: Callum Styan [email protected]