forked from couchbaselabs/tuqtng
-
Notifications
You must be signed in to change notification settings - Fork 0
/
system_pool.go
111 lines (91 loc) · 2.2 KB
/
system_pool.go
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
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
// Copyright (c) 2013 Couchbase, Inc.
// Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file
// except in compliance with the License. You may obtain a copy of the License at
// http://www.apache.org/licenses/LICENSE-2.0
// Unless required by applicable law or agreed to in writing, software distributed under the
// License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND,
// either express or implied. See the License for the specific language governing permissions
// and limitations under the License.
package system
import (
"github.com/couchbaselabs/tuqtng/catalog"
"github.com/couchbaselabs/tuqtng/query"
)
type pool struct {
site *site
id string
name string
buckets map[string]catalog.Bucket
}
func (p *pool) SiteId() string {
return p.site.Id()
}
func (p *pool) Id() string {
return p.id
}
func (p *pool) Name() string {
return p.name
}
func (p *pool) BucketIds() ([]string, query.Error) {
return p.BucketNames()
}
func (p *pool) BucketNames() ([]string, query.Error) {
rv := make([]string, len(p.buckets))
i := 0
for k, _ := range p.buckets {
rv[i] = k
i = i + 1
}
return rv, nil
}
func (p *pool) BucketById(id string) (catalog.Bucket, query.Error) {
return p.BucketByName(id)
}
func (p *pool) BucketByName(name string) (catalog.Bucket, query.Error) {
b, ok := p.buckets[name]
if !ok {
return nil, query.NewError(nil, "Bucket "+name+" not found.")
}
return b, nil
}
// newPool creates a new pool.
func newPool(s *site) (*pool, query.Error) {
p := new(pool)
p.site = s
p.id = POOL_ID
p.name = POOL_NAME
p.buckets = make(map[string]catalog.Bucket)
e := p.loadBuckets()
if e != nil {
return nil, e
}
return p, nil
}
func (p *pool) loadBuckets() (e query.Error) {
sb, e := newSitesBucket(p)
if e != nil {
return e
}
p.buckets[sb.Name()] = sb
pb, e := newPoolsBucket(p)
if e != nil {
return e
}
p.buckets[pb.Name()] = pb
bb, e := newBucketsBucket(p)
if e != nil {
return e
}
p.buckets[bb.Name()] = bb
db, e := newDualBucket(p)
if e != nil {
return e
}
p.buckets[db.Name()] = db
ib, e := newIndexesBucket(p)
if e != nil {
return e
}
p.buckets[ib.Name()] = ib
return nil
}