Browse Source

refactor

fasthttp
Chris Lu 5 years ago
parent
commit
8d94564f41
  1. 8
      weed/storage/erasure_coding/ec_encoder.go
  2. 6
      weed/storage/erasure_coding/ec_test.go

8
weed/storage/erasure_coding/ec_encoder.go

@ -26,9 +26,9 @@ const (
// all keys are sorted in ascending order // all keys are sorted in ascending order
func WriteSortedFileFromIdx(baseFileName string, ext string) (e error) { func WriteSortedFileFromIdx(baseFileName string, ext string) (e error) {
cm, err := readCompactMap(baseFileName)
nm, err := readNeedleMap(baseFileName)
if err != nil { if err != nil {
return fmt.Errorf("readCompactMap: %v", err)
return fmt.Errorf("readNeedleMap: %v", err)
} }
ecxFile, err := os.OpenFile(baseFileName+ext, os.O_TRUNC|os.O_CREATE|os.O_WRONLY, 0644) ecxFile, err := os.OpenFile(baseFileName+ext, os.O_TRUNC|os.O_CREATE|os.O_WRONLY, 0644)
@ -37,7 +37,7 @@ func WriteSortedFileFromIdx(baseFileName string, ext string) (e error) {
} }
defer ecxFile.Close() defer ecxFile.Close()
err = cm.AscendingVisit(func(value needle_map.NeedleValue) error {
err = nm.AscendingVisit(func(value needle_map.NeedleValue) error {
bytes := value.ToBytes() bytes := value.ToBytes()
_, writeErr := ecxFile.Write(bytes) _, writeErr := ecxFile.Write(bytes)
return writeErr return writeErr
@ -281,7 +281,7 @@ func rebuildEcFiles(shardHasData []bool, inputFiles []*os.File, outputFiles []*o
} }
func readCompactMap(baseFileName string) (*needle_map.MemDb, error) {
func readNeedleMap(baseFileName string) (*needle_map.MemDb, error) {
indexFile, err := os.OpenFile(baseFileName+".idx", os.O_RDONLY, 0644) indexFile, err := os.OpenFile(baseFileName+".idx", os.O_RDONLY, 0644)
if err != nil { if err != nil {
return nil, fmt.Errorf("cannot read Volume Index %s.idx: %v", baseFileName, err) return nil, fmt.Errorf("cannot read Volume Index %s.idx: %v", baseFileName, err)

6
weed/storage/erasure_coding/ec_test.go

@ -41,9 +41,9 @@ func TestEncodingDecoding(t *testing.T) {
} }
func validateFiles(baseFileName string) error { func validateFiles(baseFileName string) error {
cm, err := readCompactMap(baseFileName)
nm, err := readNeedleMap(baseFileName)
if err != nil { if err != nil {
return fmt.Errorf("readCompactMap: %v", err)
return fmt.Errorf("readNeedleMap: %v", err)
} }
datFile, err := os.OpenFile(baseFileName+".dat", os.O_RDONLY, 0) datFile, err := os.OpenFile(baseFileName+".dat", os.O_RDONLY, 0)
@ -60,7 +60,7 @@ func validateFiles(baseFileName string) error {
ecFiles, err := openEcFiles(baseFileName, true) ecFiles, err := openEcFiles(baseFileName, true)
defer closeEcFiles(ecFiles) defer closeEcFiles(ecFiles)
err = cm.AscendingVisit(func(value needle_map.NeedleValue) error {
err = nm.AscendingVisit(func(value needle_map.NeedleValue) error {
return assertSame(datFile, fi.Size(), ecFiles, value.Offset, value.Size) return assertSame(datFile, fi.Size(), ecFiles, value.Offset, value.Size)
}) })
if err != nil { if err != nil {

Loading…
Cancel
Save