datamanager: refactor ReadWal
make ReadWal directly return a *WalHeader
This commit is contained in:
parent
cd5c5a20ed
commit
9c0eb3d7ef
|
@ -91,17 +91,10 @@ func (d *DataManager) walIndex(ctx context.Context, wals []*WalData) (walIndex,
|
||||||
wimap := map[string]map[string]*Action{}
|
wimap := map[string]map[string]*Action{}
|
||||||
|
|
||||||
for _, walData := range wals {
|
for _, walData := range wals {
|
||||||
walFilef, err := d.ReadWal(walData.WalSequence)
|
header, err := d.ReadWal(walData.WalSequence)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
dec := json.NewDecoder(walFilef)
|
|
||||||
var header *WalHeader
|
|
||||||
if err = dec.Decode(&header); err != nil && err != io.EOF {
|
|
||||||
walFilef.Close()
|
|
||||||
return nil, err
|
|
||||||
}
|
|
||||||
walFilef.Close()
|
|
||||||
|
|
||||||
walFile, err := d.ReadWalData(header.WalDataFileID)
|
walFile, err := d.ReadWalData(header.WalDataFileID)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
@ -109,7 +102,7 @@ func (d *DataManager) walIndex(ctx context.Context, wals []*WalData) (walIndex,
|
||||||
}
|
}
|
||||||
defer walFile.Close()
|
defer walFile.Close()
|
||||||
|
|
||||||
dec = json.NewDecoder(walFile)
|
dec := json.NewDecoder(walFile)
|
||||||
for {
|
for {
|
||||||
var action *Action
|
var action *Action
|
||||||
|
|
||||||
|
|
|
@ -141,8 +141,19 @@ func (d *DataManager) HasOSTWal(walseq string) (bool, error) {
|
||||||
return true, nil
|
return true, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (d *DataManager) ReadWal(walseq string) (io.ReadCloser, error) {
|
func (d *DataManager) ReadWal(walseq string) (*WalHeader, error) {
|
||||||
return d.ost.ReadObject(d.storageWalStatusFile(walseq) + ".committed")
|
walFilef, err := d.ost.ReadObject(d.storageWalStatusFile(walseq) + ".committed")
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
defer walFilef.Close()
|
||||||
|
dec := json.NewDecoder(walFilef)
|
||||||
|
var header *WalHeader
|
||||||
|
if err = dec.Decode(&header); err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
|
||||||
|
return header, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (d *DataManager) ReadWalData(walFileID string) (io.ReadCloser, error) {
|
func (d *DataManager) ReadWalData(walFileID string) (io.ReadCloser, error) {
|
||||||
|
|
|
@ -197,17 +197,10 @@ func (r *ReadDB) SyncFromWals(ctx context.Context, startWalSeq, endWalSeq string
|
||||||
insertfunc := func(walFiles []*datamanager.WalFile) error {
|
insertfunc := func(walFiles []*datamanager.WalFile) error {
|
||||||
err := r.rdb.Do(ctx, func(tx *db.Tx) error {
|
err := r.rdb.Do(ctx, func(tx *db.Tx) error {
|
||||||
for _, walFile := range walFiles {
|
for _, walFile := range walFiles {
|
||||||
walFilef, err := r.dm.ReadWal(walFile.WalSequence)
|
header, err := r.dm.ReadWal(walFile.WalSequence)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
dec := json.NewDecoder(walFilef)
|
|
||||||
var header *datamanager.WalHeader
|
|
||||||
if err = dec.Decode(&header); err != nil && err != io.EOF {
|
|
||||||
walFilef.Close()
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
walFilef.Close()
|
|
||||||
if err := r.insertCommittedWalSequence(tx, walFile.WalSequence); err != nil {
|
if err := r.insertCommittedWalSequence(tx, walFile.WalSequence); err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
|
@ -735,17 +735,10 @@ func (r *ReadDB) SyncFromWals(ctx context.Context, startWalSeq, endWalSeq string
|
||||||
insertfunc := func(walFiles []*datamanager.WalFile) error {
|
insertfunc := func(walFiles []*datamanager.WalFile) error {
|
||||||
err := r.rdb.Do(ctx, func(tx *db.Tx) error {
|
err := r.rdb.Do(ctx, func(tx *db.Tx) error {
|
||||||
for _, walFile := range walFiles {
|
for _, walFile := range walFiles {
|
||||||
walFilef, err := r.dm.ReadWal(walFile.WalSequence)
|
header, err := r.dm.ReadWal(walFile.WalSequence)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
dec := json.NewDecoder(walFilef)
|
|
||||||
var header *datamanager.WalHeader
|
|
||||||
if err = dec.Decode(&header); err != nil && err != io.EOF {
|
|
||||||
walFilef.Close()
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
walFilef.Close()
|
|
||||||
if err := r.insertCommittedWalSequenceOST(tx, walFile.WalSequence); err != nil {
|
if err := r.insertCommittedWalSequenceOST(tx, walFile.WalSequence); err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue