filer: close stores if interrupted

This commit is contained in:
Chris Lu 2020-03-14 20:30:26 -07:00
parent d022b6bc0e
commit 7b37178716
9 changed files with 41 additions and 0 deletions

View file

@ -184,3 +184,7 @@ func (store *AbstractSqlStore) ListDirectoryEntries(ctx context.Context, fullpat
return entries, nil
}
func (store *AbstractSqlStore) Shutdown() {
store.DB.Close()
}

View file

@ -154,3 +154,7 @@ func (store *CassandraStore) ListDirectoryEntries(ctx context.Context, fullpath
return entries, err
}
func (store *CassandraStore) Shutdown() {
store.session.Close()
}

View file

@ -196,3 +196,7 @@ func getNameFromKey(key []byte) string {
return string(key[sepIndex+1:])
}
func (store *EtcdStore) Shutdown() {
store.client.Close()
}

View file

@ -308,3 +308,7 @@ func (f *Filer) cacheSetDirectory(dirpath string, dirEntry *Entry, level int) {
f.directoryCache.Set(dirpath, dirEntry, time.Duration(minutes)*time.Minute)
}
func (f *Filer) Shutdown() {
f.store.Shutdown()
}

View file

@ -25,6 +25,8 @@ type FilerStore interface {
BeginTransaction(ctx context.Context) (context.Context, error)
CommitTransaction(ctx context.Context) error
RollbackTransaction(ctx context.Context) error
Shutdown()
}
type FilerStoreWrapper struct {
@ -133,3 +135,7 @@ func (fsw *FilerStoreWrapper) CommitTransaction(ctx context.Context) error {
func (fsw *FilerStoreWrapper) RollbackTransaction(ctx context.Context) error {
return fsw.actualStore.RollbackTransaction(ctx)
}
func (fsw *FilerStoreWrapper) Shutdown() {
fsw.actualStore.Shutdown()
}

View file

@ -216,3 +216,7 @@ func getNameFromKey(key []byte) string {
return string(key[sepIndex+1:])
}
func (store *LevelDBStore) Shutdown() {
store.db.Close()
}

View file

@ -236,3 +236,9 @@ func hashToBytes(dir string, dbCount int) ([]byte, int) {
return b, int(x) % dbCount
}
func (store *LevelDB2Store) Shutdown() {
for d := 0; d < store.dbCount; d++ {
store.dbs[d].Close()
}
}

View file

@ -180,3 +180,8 @@ func (store *UniversalRedisStore) ListDirectoryEntries(ctx context.Context, full
func genDirectoryListKey(dir string) (dirList string) {
return dir + DIR_LIST_MARKER
}
func (store *UniversalRedisStore) Shutdown() {
store.Client.Close()
}

View file

@ -102,6 +102,10 @@ func NewFilerServer(defaultMux, readonlyMux *http.ServeMux, option *FilerOption)
maybeStartMetrics(fs, option)
util.OnInterrupt(func() {
fs.filer.Shutdown()
})
return fs, nil
}