untangle fsjournal dependencies

This commit is contained in:
Łukasz Magiera
2021-08-26 15:44:45 +02:00
parent 5366821144
commit b094e0913d
4 changed files with 19 additions and 12 deletions
+13 -9
View File
@@ -1,4 +1,4 @@
package journal
package fsjournal
import (
"encoding/json"
@@ -6,17 +6,21 @@ import (
"os"
"path/filepath"
logging "github.com/ipfs/go-log/v2"
"golang.org/x/xerrors"
"github.com/filecoin-project/lotus/build"
"github.com/filecoin-project/lotus/journal"
"github.com/filecoin-project/lotus/node/repo"
)
var log = logging.Logger("fsjournal")
const RFC3339nocolon = "2006-01-02T150405Z0700"
// fsJournal is a basic journal backed by files on a filesystem.
type fsJournal struct {
EventTypeRegistry
journal.EventTypeRegistry
dir string
sizeLimit int64
@@ -24,7 +28,7 @@ type fsJournal struct {
fi *os.File
fSize int64
incoming chan *Event
incoming chan *journal.Event
closing chan struct{}
closed chan struct{}
@@ -32,17 +36,17 @@ type fsJournal struct {
// OpenFSJournal constructs a rolling filesystem journal, with a default
// per-file size limit of 1GiB.
func OpenFSJournal(lr repo.LockedRepo, disabled DisabledEvents) (Journal, error) {
func OpenFSJournal(lr repo.LockedRepo, disabled journal.DisabledEvents) (journal.Journal, error) {
dir := filepath.Join(lr.Path(), "journal")
if err := os.MkdirAll(dir, 0755); err != nil {
return nil, fmt.Errorf("failed to mk directory %s for file journal: %w", dir, err)
}
f := &fsJournal{
EventTypeRegistry: NewEventTypeRegistry(disabled),
EventTypeRegistry: journal.NewEventTypeRegistry(disabled),
dir: dir,
sizeLimit: 1 << 30,
incoming: make(chan *Event, 32),
incoming: make(chan *journal.Event, 32),
closing: make(chan struct{}),
closed: make(chan struct{}),
}
@@ -56,7 +60,7 @@ func OpenFSJournal(lr repo.LockedRepo, disabled DisabledEvents) (Journal, error)
return f, nil
}
func (f *fsJournal) RecordEvent(evtType EventType, supplier func() interface{}) {
func (f *fsJournal) RecordEvent(evtType journal.EventType, supplier func() interface{}) {
defer func() {
if r := recover(); r != nil {
log.Warnf("recovered from panic while recording journal event; type=%s, err=%v", evtType, r)
@@ -67,7 +71,7 @@ func (f *fsJournal) RecordEvent(evtType EventType, supplier func() interface{})
return
}
je := &Event{
je := &journal.Event{
EventType: evtType,
Timestamp: build.Clock.Now(),
Data: supplier(),
@@ -85,7 +89,7 @@ func (f *fsJournal) Close() error {
return nil
}
func (f *fsJournal) putEvent(evt *Event) error {
func (f *fsJournal) putEvent(evt *journal.Event) error {
b, err := json.Marshal(evt)
if err != nil {
return err