fix: merge

This commit is contained in:
Jon Lundy 2022-08-10 21:18:57 -06:00
parent 23639bc306
commit fd97f2ff17
Signed by untrusted user who does not match committer: xuu
GPG Key ID: C63E6D61F3035024
2 changed files with 25 additions and 8 deletions

View File

@ -1,17 +1,17 @@
package main
import (
"fmt"
"context"
"fmt"
"log"
"net/http"
"os"
"os/signal"
"time"
"golang.org/x/sync/errgroup"
"github.com/99designs/gqlgen/graphql/handler"
"github.com/rs/cors"
"golang.org/x/sync/errgroup"
"github.com/sour-is/ev/api/gql_ev"
"github.com/sour-is/ev/internal/graph"

View File

@ -17,8 +17,12 @@ import (
"github.com/sour-is/ev/pkg/math"
)
type openlogs struct {
logs map[string]*locker.Locked[wal.Log]
}
type diskStore struct {
path string
openlogs *locker.Locked[openlogs]
}
const AppendOnly = es.AppendOnly
@ -48,13 +52,26 @@ func (diskStore) Open(_ context.Context, dsn string) (driver.Driver, error) {
}
}
return &diskStore{path: path}, nil
logs := &openlogs{logs: make(map[string]*locker.Locked[wal.Log])}
return &diskStore{path: path, openlogs: locker.New(logs)}, nil
}
func (ds *diskStore) EventLog(ctx context.Context, streamID string) (driver.EventLog, error) {
el := &eventLog{streamID: streamID}
return el, ds.openlogs.Modify(ctx, func(openlogs *openlogs) error {
if events, ok := openlogs.logs[streamID]; ok {
el.events = events
return nil
}
l, err := wal.Open(filepath.Join(ds.path, streamID), wal.DefaultOptions)
if err != nil {
return err
}
el.events = locker.New(l)
return el, err
openlogs.logs[streamID] = el.events
return nil
})
}
type eventLog struct {