This repository has been archived by the owner on Aug 31, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 33
(VDB-371) recheck queued storage #86
Merged
Merged
Changes from all commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
2d684c5
Extract storage diff fetching behind an interface
rmulhol bf4b168
Add get/delete functions to storage queue
rmulhol 6a86de8
(VDB-371) Recheck queued storage
rmulhol d77f3fe
Don't pass empty row to channel on error
rmulhol 76ab914
Add license
rmulhol b036053
Queue storage diffs if transformer execution fails
rmulhol 6716c3b
Make queue recheck interval configurable via CLI
rmulhol 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
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 |
---|---|---|
@@ -0,0 +1,50 @@ | ||
// VulcanizeDB | ||
// Copyright © 2019 Vulcanize | ||
|
||
// This program is free software: you can redistribute it and/or modify | ||
// it under the terms of the GNU Affero General Public License as published by | ||
// the Free Software Foundation, either version 3 of the License, or | ||
// (at your option) any later version. | ||
|
||
// This program is distributed in the hope that it will be useful, | ||
// but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
// GNU Affero General Public License for more details. | ||
|
||
// You should have received a copy of the GNU Affero General Public License | ||
// along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
|
||
package fetcher | ||
|
||
import ( | ||
"github.com/vulcanize/vulcanizedb/libraries/shared/storage/utils" | ||
"github.com/vulcanize/vulcanizedb/pkg/fs" | ||
"strings" | ||
) | ||
|
||
type IStorageFetcher interface { | ||
FetchStorageDiffs(chan<- utils.StorageDiffRow, chan<- error) | ||
} | ||
|
||
type CsvTailStorageFetcher struct { | ||
tailer fs.Tailer | ||
} | ||
|
||
func NewCsvTailStorageFetcher(tailer fs.Tailer) CsvTailStorageFetcher { | ||
return CsvTailStorageFetcher{tailer: tailer} | ||
} | ||
|
||
func (storageFetcher CsvTailStorageFetcher) FetchStorageDiffs(out chan<- utils.StorageDiffRow, errs chan<- error) { | ||
t, tailErr := storageFetcher.tailer.Tail() | ||
if tailErr != nil { | ||
errs <- tailErr | ||
} | ||
for line := range t.Lines { | ||
row, parseErr := utils.FromStrings(strings.Split(line.Text, ",")) | ||
if parseErr != nil { | ||
errs <- parseErr | ||
} else { | ||
out <- row | ||
} | ||
} | ||
} |
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 |
---|---|---|
@@ -0,0 +1,99 @@ | ||
// VulcanizeDB | ||
// Copyright © 2019 Vulcanize | ||
|
||
// This program is free software: you can redistribute it and/or modify | ||
// it under the terms of the GNU Affero General Public License as published by | ||
// the Free Software Foundation, either version 3 of the License, or | ||
// (at your option) any later version. | ||
|
||
// This program is distributed in the hope that it will be useful, | ||
// but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
// GNU Affero General Public License for more details. | ||
|
||
// You should have received a copy of the GNU Affero General Public License | ||
// along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
|
||
package fetcher_test | ||
|
||
import ( | ||
"fmt" | ||
"strings" | ||
"time" | ||
|
||
"github.com/ethereum/go-ethereum/common" | ||
"github.com/hpcloud/tail" | ||
. "github.com/onsi/ginkgo" | ||
. "github.com/onsi/gomega" | ||
|
||
"github.com/vulcanize/vulcanizedb/libraries/shared/fetcher" | ||
"github.com/vulcanize/vulcanizedb/libraries/shared/storage/utils" | ||
"github.com/vulcanize/vulcanizedb/pkg/fakes" | ||
) | ||
|
||
var _ = Describe("Csv Tail Storage Fetcher", func() { | ||
var ( | ||
errorsChannel chan error | ||
mockTailer *fakes.MockTailer | ||
rowsChannel chan utils.StorageDiffRow | ||
storageFetcher fetcher.CsvTailStorageFetcher | ||
) | ||
|
||
BeforeEach(func() { | ||
errorsChannel = make(chan error) | ||
rowsChannel = make(chan utils.StorageDiffRow) | ||
mockTailer = fakes.NewMockTailer() | ||
storageFetcher = fetcher.NewCsvTailStorageFetcher(mockTailer) | ||
}) | ||
|
||
It("adds error to errors channel if tailing file fails", func(done Done) { | ||
mockTailer.TailErr = fakes.FakeError | ||
|
||
go storageFetcher.FetchStorageDiffs(rowsChannel, errorsChannel) | ||
|
||
Expect(<-errorsChannel).To(MatchError(fakes.FakeError)) | ||
close(done) | ||
}) | ||
|
||
It("adds parsed csv row to rows channel for storage diff", func(done Done) { | ||
line := getFakeLine() | ||
|
||
go storageFetcher.FetchStorageDiffs(rowsChannel, errorsChannel) | ||
mockTailer.Lines <- line | ||
|
||
expectedRow, err := utils.FromStrings(strings.Split(line.Text, ",")) | ||
Expect(err).NotTo(HaveOccurred()) | ||
Expect(<-rowsChannel).To(Equal(expectedRow)) | ||
close(done) | ||
}) | ||
|
||
It("adds error to errors channel if parsing csv fails", func(done Done) { | ||
line := &tail.Line{Text: "invalid"} | ||
|
||
go storageFetcher.FetchStorageDiffs(rowsChannel, errorsChannel) | ||
mockTailer.Lines <- line | ||
|
||
Expect(<-errorsChannel).To(HaveOccurred()) | ||
select { | ||
case <-rowsChannel: | ||
Fail("value passed to rows channel on error") | ||
default: | ||
Succeed() | ||
} | ||
close(done) | ||
}) | ||
}) | ||
|
||
func getFakeLine() *tail.Line { | ||
address := common.HexToAddress("0x1234567890abcdef") | ||
blockHash := []byte{4, 5, 6} | ||
blockHeight := int64(789) | ||
storageKey := []byte{9, 8, 7} | ||
storageValue := []byte{6, 5, 4} | ||
return &tail.Line{ | ||
Text: fmt.Sprintf("%s,%s,%d,%s,%s", common.Bytes2Hex(address.Bytes()), common.Bytes2Hex(blockHash), | ||
blockHeight, common.Bytes2Hex(storageKey), common.Bytes2Hex(storageValue)), | ||
Time: time.Time{}, | ||
Err: nil, | ||
} | ||
} |
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 |
---|---|---|
@@ -0,0 +1,39 @@ | ||
// VulcanizeDB | ||
// Copyright © 2019 Vulcanize | ||
|
||
// This program is free software: you can redistribute it and/or modify | ||
// it under the terms of the GNU Affero General Public License as published by | ||
// the Free Software Foundation, either version 3 of the License, or | ||
// (at your option) any later version. | ||
|
||
// This program is distributed in the hope that it will be useful, | ||
// but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
// GNU Affero General Public License for more details. | ||
|
||
// You should have received a copy of the GNU Affero General Public License | ||
// along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
|
||
package mocks | ||
|
||
import "github.com/vulcanize/vulcanizedb/libraries/shared/storage/utils" | ||
|
||
type MockStorageFetcher struct { | ||
RowsToReturn []utils.StorageDiffRow | ||
ErrsToReturn []error | ||
} | ||
|
||
func NewMockStorageFetcher() *MockStorageFetcher { | ||
return &MockStorageFetcher{} | ||
} | ||
|
||
func (fetcher *MockStorageFetcher) FetchStorageDiffs(out chan<- utils.StorageDiffRow, errs chan<- error) { | ||
defer close(out) | ||
defer close(errs) | ||
for _, err := range fetcher.ErrsToReturn { | ||
errs <- err | ||
} | ||
for _, row := range fetcher.RowsToReturn { | ||
out <- row | ||
} | ||
} |
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.
Could add license header