Exemplo n.º 1
0
func (r *Reader) corrupt(n int, reason string, skip bool) error {
	if r.dropper != nil {
		r.dropper.Drop(&ErrCorrupted{n, reason})
	}
	if r.strict && !skip {
		r.err = errors.NewErrCorrupted(nil, &ErrCorrupted{n, reason})
		return r.err
	}
	return errSkip
}
Exemplo n.º 2
0
func newErrIkeyCorrupted(ikey []byte, reason string) error {
	return errors.NewErrCorrupted(nil, &ErrIkeyCorrupted{append([]byte{}, ikey...), reason})
}
Exemplo n.º 3
0
func newErrManifestCorrupted(f storage.File, field, reason string) error {
	return errors.NewErrCorrupted(f, &ErrManifestCorrupted{field, reason})
}
Exemplo n.º 4
0
// Check and clean files.
func (db *DB) checkAndCleanFiles() error {
	v := db.s.version()
	defer v.release()

	tablesMap := make(map[uint64]bool)
	for _, tables := range v.tables {
		for _, t := range tables {
			tablesMap[t.file.Num()] = false
		}
	}

	files, err := db.s.getFiles(storage.TypeAll)
	if err != nil {
		return err
	}

	var nTables int
	var rem []storage.File
	for _, f := range files {
		keep := true
		switch f.Type() {
		case storage.TypeManifest:
			keep = f.Num() >= db.s.manifestFile.Num()
		case storage.TypeJournal:
			if db.frozenJournalFile != nil {
				keep = f.Num() >= db.frozenJournalFile.Num()
			} else {
				keep = f.Num() >= db.journalFile.Num()
			}
		case storage.TypeTable:
			_, keep = tablesMap[f.Num()]
			if keep {
				tablesMap[f.Num()] = true
				nTables++
			}
		}

		if !keep {
			rem = append(rem, f)
		}
	}

	if nTables != len(tablesMap) {
		var missing []*storage.FileInfo
		for num, present := range tablesMap {
			if !present {
				missing = append(missing, &storage.FileInfo{Type: storage.TypeTable, Num: num})
				db.logf("db@janitor table missing @%d", num)
			}
		}
		return errors.NewErrCorrupted(nil, &errors.ErrMissingFiles{Files: missing})
	}

	db.logf("db@janitor F·%d G·%d", len(files), len(rem))
	for _, f := range rem {
		db.logf("db@janitor removing %s-%d", f.Type(), f.Num())
		if err := f.Remove(); err != nil {
			return err
		}
	}
	return nil
}
Exemplo n.º 5
0
func newErrBatchCorrupted(reason string) error {
	return errors.NewErrCorrupted(nil, &ErrBatchCorrupted{reason})
}