File: daemonstore.go

package info (click to toggle)
golang-github-containerd-nydus-snapshotter 0.13.4-2.1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 3,824 kB
  • sloc: sh: 470; makefile: 129
file content (64 lines) | stat: -rw-r--r-- 1,761 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
/*
 * Copyright (c) 2020. Ant Group. All rights reserved.
 * Copyright (c) 2022. Nydus Developers. All rights reserved.
 *
 * SPDX-License-Identifier: Apache-2.0
 */

package store

import (
	"context"

	"github.com/containerd/nydus-snapshotter/pkg/daemon"
	"github.com/containerd/nydus-snapshotter/pkg/rafs"
)

type DaemonRafsStore struct {
	db *Database // save daemons in database
}

func NewDaemonRafsStore(db *Database) (*DaemonRafsStore, error) {
	return &DaemonRafsStore{
		db: db,
	}, nil
}

// If the daemon is inserted to DB before, return error ErrAlreadyExisted.
func (s *DaemonRafsStore) AddDaemon(d *daemon.Daemon) error {
	// Save daemon info in case snapshotter restarts so that we can restore the
	// daemon states and reconnect the daemons.
	return s.db.SaveDaemon(context.TODO(), d)
}

func (s *DaemonRafsStore) UpdateDaemon(d *daemon.Daemon) error {
	return s.db.UpdateDaemon(context.TODO(), d)
}

func (s *DaemonRafsStore) DeleteDaemon(id string) error {
	return s.db.DeleteDaemon(context.TODO(), id)
}

func (s *DaemonRafsStore) WalkDaemons(ctx context.Context, cb func(d *daemon.ConfigState) error) error {
	return s.db.WalkDaemons(ctx, cb)
}

func (s *DaemonRafsStore) CleanupDaemons(ctx context.Context) error {
	return s.db.CleanupDaemons(ctx)
}

func (s *DaemonRafsStore) AddRafsInstance(r *rafs.Rafs) error {
	return s.db.AddRafsInstance(context.TODO(), r)
}

func (s *DaemonRafsStore) DeleteRafsInstance(snapshotID string) error {
	return s.db.DeleteRafsInstance(context.TODO(), snapshotID)
}

func (s *DaemonRafsStore) WalkRafsInstances(ctx context.Context, cb func(*rafs.Rafs) error) error {
	return s.db.WalkRafsInstances(ctx, cb)
}

func (s *DaemonRafsStore) NextInstanceSeq() (uint64, error) {
	return s.db.NextInstanceSeq()
}