-
Notifications
You must be signed in to change notification settings - Fork 264
/
funcs.go
201 lines (188 loc) · 5.51 KB
/
funcs.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
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
// Copyright 2021 Matrix Origin
//
// 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 blockio
import (
"context"
"github.com/matrixorigin/matrixone/pkg/vm/engine/tae/containers"
"github.com/matrixorigin/matrixone/pkg/common/mpool"
"github.com/matrixorigin/matrixone/pkg/container/batch"
"github.com/matrixorigin/matrixone/pkg/container/types"
"github.com/matrixorigin/matrixone/pkg/container/vector"
"github.com/matrixorigin/matrixone/pkg/fileservice"
"github.com/matrixorigin/matrixone/pkg/objectio"
)
func LoadColumnsData(
ctx context.Context,
metaType objectio.DataMetaType,
cols []uint16,
typs []types.Type,
fs fileservice.FileService,
location objectio.Location,
m *mpool.MPool,
policy fileservice.Policy,
) (bat *batch.Batch, release func(), err error) {
name := location.Name()
var meta objectio.ObjectMeta
var ioVectors *fileservice.IOVector
if meta, err = objectio.FastLoadObjectMeta(ctx, &location, false, fs); err != nil {
return
}
dataMeta := meta.MustGetMeta(metaType)
if ioVectors, err = objectio.ReadOneBlock(ctx, &dataMeta, name.String(), location.ID(), cols, typs, m, fs, policy); err != nil {
return
}
release = func() {
objectio.ReleaseIOVector(ioVectors)
}
bat = batch.NewWithSize(len(cols))
var obj any
for i := range cols {
obj, err = objectio.Decode(ioVectors.Entries[i].CachedData.Bytes())
if err != nil {
return
}
bat.Vecs[i] = obj.(*vector.Vector)
bat.SetRowCount(bat.Vecs[i].Length())
}
//TODO call CachedData.Release
return
}
func LoadColumnsData2(
ctx context.Context,
metaType objectio.DataMetaType,
cols []uint16,
typs []types.Type,
fs fileservice.FileService,
location objectio.Location,
policy fileservice.Policy,
needCopy bool,
vPool *containers.VectorPool,
) (vectors []containers.Vector, release func(), err error) {
name := location.Name()
var meta objectio.ObjectMeta
var ioVectors *fileservice.IOVector
if meta, err = objectio.FastLoadObjectMeta(ctx, &location, false, fs); err != nil {
return
}
dataMeta := meta.MustGetMeta(metaType)
if ioVectors, err = objectio.ReadOneBlock(ctx, &dataMeta, name.String(), location.ID(), cols, typs, nil, fs, policy); err != nil {
return
}
defer func() {
if needCopy {
objectio.ReleaseIOVector(ioVectors)
return
}
release = func() {
objectio.ReleaseIOVector(ioVectors)
}
}()
var obj any
vectors = make([]containers.Vector, len(cols))
for i := range cols {
obj, err = objectio.Decode(ioVectors.Entries[i].CachedData.Bytes())
if err != nil {
return
}
var vec containers.Vector
if needCopy {
if vec, err = containers.CloneVector(
obj.(*vector.Vector),
vPool.GetMPool(),
vPool,
); err != nil {
return
}
} else {
vec = containers.ToTNVector(obj.(*vector.Vector), nil)
}
vectors[i] = vec
}
if err != nil {
for _, col := range vectors {
if col != nil {
col.Close()
}
}
return nil, release, err
}
return
}
func LoadColumns(
ctx context.Context,
cols []uint16,
typs []types.Type,
fs fileservice.FileService,
location objectio.Location,
m *mpool.MPool,
policy fileservice.Policy,
) (bat *batch.Batch, release func(), err error) {
return LoadColumnsData(ctx, objectio.SchemaData, cols, typs, fs, location, m, policy)
}
func LoadTombstoneColumns(
ctx context.Context,
cols []uint16,
typs []types.Type,
fs fileservice.FileService,
location objectio.Location,
m *mpool.MPool,
) (bat *batch.Batch, release func(), err error) {
return LoadColumnsData(ctx, objectio.SchemaTombstone, cols, typs, fs, location, m, fileservice.Policy(0))
}
// LoadColumns2 load columns data from file service for TN
// need to copy data from vPool to avoid releasing cache
func LoadColumns2(
ctx context.Context,
cols []uint16,
typs []types.Type,
fs fileservice.FileService,
location objectio.Location,
policy fileservice.Policy,
needCopy bool,
vPool *containers.VectorPool,
) (vectors []containers.Vector, release func(), err error) {
return LoadColumnsData2(ctx, objectio.SchemaData, cols, typs, fs, location, policy, needCopy, vPool)
}
// LoadTombstoneColumns2 load tombstone data from file service for TN
// need to copy data from vPool to avoid releasing cache
func LoadTombstoneColumns2(
ctx context.Context,
cols []uint16,
typs []types.Type,
fs fileservice.FileService,
location objectio.Location,
needCopy bool,
vPool *containers.VectorPool,
) (vectors []containers.Vector, release func(), err error) {
return LoadColumnsData2(ctx, objectio.SchemaTombstone, cols, typs, fs, location, fileservice.Policy(0), needCopy, vPool)
}
func LoadOneBlock(
ctx context.Context,
fs fileservice.FileService,
key objectio.Location,
metaType objectio.DataMetaType,
) (*batch.Batch, error) {
meta, err := objectio.FastLoadObjectMeta(ctx, &key, false, fs)
if err != nil {
return nil, err
}
data := meta.MustGetMeta(metaType)
idxes := make([]uint16, data.BlockHeader().ColumnCount())
for i := range idxes {
idxes[i] = uint16(i)
}
bat, err := objectio.ReadOneBlockAllColumns(ctx, &data, key.Name().String(),
uint32(key.ID()), idxes, fileservice.SkipAllCache, fs)
return bat, err
}