-
Notifications
You must be signed in to change notification settings - Fork 63
/
blockstore.go
632 lines (582 loc) · 18.9 KB
/
blockstore.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
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
package blockstore
import (
"context"
"encoding/json"
"fmt"
"log"
"math"
"os"
"strings"
"sync"
"time"
)
type FileOptsType struct {
MaxSize int64
Circular bool
IJson bool
}
type FileMeta = map[string]any
type FileInfo struct {
BlockId string
Name string
Size int64
CreatedTs int64
ModTs int64
Opts FileOptsType
Meta FileMeta
}
const UnitsKB = 1024 * 1024
const UnitsMB = 1024 * UnitsKB
const UnitsGB = 1024 * UnitsMB
const MaxBlockSize = int64(128 * UnitsKB)
const DefaultFlushTimeout = 1 * time.Second
type CacheEntry struct {
Lock *sync.Mutex
CacheTs int64
Info *FileInfo
DataBlocks []*CacheBlock
Refs int64
}
func (c *CacheEntry) IncRefs() {
c.Refs += 1
}
func (c *CacheEntry) DecRefs() {
c.Refs -= 1
}
type CacheBlock struct {
data []byte
size int
dirty bool
}
func MakeCacheEntry(info *FileInfo) *CacheEntry {
rtn := &CacheEntry{Lock: &sync.Mutex{}, CacheTs: int64(time.Now().UnixMilli()), Info: info, DataBlocks: []*CacheBlock{}, Refs: 0}
return rtn
}
// add ctx context.Context to all these methods
type BlockStore interface {
MakeFile(ctx context.Context, blockId string, name string, meta FileMeta, opts FileOptsType) error
WriteFile(ctx context.Context, blockId string, name string, meta FileMeta, opts FileOptsType, data []byte) (int, error)
AppendData(ctx context.Context, blockId string, name string, p []byte) (int, error)
WriteAt(ctx context.Context, blockId string, name string, p []byte, off int64) (int, error)
ReadAt(ctx context.Context, blockId string, name string, p *[]byte, off int64) (int, error)
Stat(ctx context.Context, blockId string, name string) (FileInfo, error)
CollapseIJson(ctx context.Context, blockId string, name string) error
WriteMeta(ctx context.Context, blockId string, name string, meta FileMeta) error
DeleteFile(ctx context.Context, blockId string, name string) error
DeleteBlock(ctx context.Context, blockId string) error
ListFiles(ctx context.Context, blockId string) []*FileInfo
FlushCache(ctx context.Context) error
GetAllBlockIds(ctx context.Context) []string
}
var blockstoreCache map[string]*CacheEntry = make(map[string]*CacheEntry)
var globalLock *sync.Mutex = &sync.Mutex{}
var appendLock *sync.Mutex = &sync.Mutex{}
var flushTimeout = DefaultFlushTimeout
var lastWriteTime time.Time
// for testing
func clearCache() {
globalLock.Lock()
defer globalLock.Unlock()
blockstoreCache = make(map[string]*CacheEntry)
}
func InsertFileIntoDB(ctx context.Context, fileInfo FileInfo) error {
metaJson, err := json.Marshal(fileInfo.Meta)
if err != nil {
return fmt.Errorf("error writing file %s to db: %v", fileInfo.Name, err)
}
txErr := WithTx(ctx, func(tx *TxWrap) error {
query := `INSERT INTO block_file VALUES (?, ?, ?, ?, ?, ?, ?, ?)`
tx.Exec(query, fileInfo.BlockId, fileInfo.Name, fileInfo.Opts.MaxSize, fileInfo.Opts.Circular, fileInfo.Size, fileInfo.CreatedTs, fileInfo.ModTs, metaJson)
return nil
})
if txErr != nil {
return fmt.Errorf("error writing file %s to db: %v", fileInfo.Name, txErr)
}
return nil
}
func WriteFileToDB(ctx context.Context, fileInfo FileInfo) error {
metaJson, err := json.Marshal(fileInfo.Meta)
if err != nil {
return fmt.Errorf("error writing file %s to db: %v", fileInfo.Name, err)
}
txErr := WithTx(ctx, func(tx *TxWrap) error {
query := `UPDATE block_file SET blockid = ?, name = ?, maxsize = ?, circular = ?, size = ?, createdts = ?, modts = ?, meta = ? where blockid = ? and name = ?`
tx.Exec(query, fileInfo.BlockId, fileInfo.Name, fileInfo.Opts.MaxSize, fileInfo.Opts.Circular, fileInfo.Size, fileInfo.CreatedTs, fileInfo.ModTs, metaJson, fileInfo.BlockId, fileInfo.Name)
return nil
})
if txErr != nil {
return fmt.Errorf("error writing file %s to db: %v", fileInfo.Name, txErr)
}
return nil
}
func WriteDataBlockToDB(ctx context.Context, blockId string, name string, index int, data []byte) error {
txErr := WithTx(ctx, func(tx *TxWrap) error {
query := `REPLACE INTO block_data values (?, ?, ?, ?)`
tx.Exec(query, blockId, name, index, data)
return nil
})
if txErr != nil {
return fmt.Errorf("error writing data block to db: %v", txErr)
}
return nil
}
func MakeFile(ctx context.Context, blockId string, name string, meta FileMeta, opts FileOptsType) error {
curTs := time.Now().UnixMilli()
fileInfo := FileInfo{BlockId: blockId, Name: name, Size: 0, CreatedTs: curTs, ModTs: curTs, Opts: opts, Meta: meta}
err := InsertFileIntoDB(ctx, fileInfo)
if err != nil {
return err
}
curCacheEntry := MakeCacheEntry(&fileInfo)
SetCacheEntry(ctx, GetCacheId(blockId, name), curCacheEntry)
return nil
}
func WriteToCacheBlockNum(ctx context.Context, blockId string, name string, p []byte, pos int, length int, cacheNum int, pullFromDB bool) (int64, int, error) {
cacheEntry, err := GetCacheEntryOrPopulate(ctx, blockId, name)
if err != nil {
return 0, 0, err
}
cacheEntry.IncRefs()
cacheEntry.Lock.Lock()
defer cacheEntry.Lock.Unlock()
block, err := GetCacheBlock(ctx, blockId, name, cacheNum, pullFromDB)
if err != nil {
return 0, 0, fmt.Errorf("error getting cache block: %v", err)
}
var bytesWritten = 0
blockLen := len(block.data)
fileMaxSize := cacheEntry.Info.Opts.MaxSize
maxWriteSize := fileMaxSize - (int64(cacheNum) * MaxBlockSize)
numLeftPad := int64(0)
if pos > blockLen {
numLeftPad = int64(pos - blockLen)
leftPadBytes := []byte{}
for index := 0; index < int(numLeftPad); index++ {
leftPadBytes = append(leftPadBytes, 0)
}
leftPadPos := int64(pos) - numLeftPad
b, err := WriteToCacheBuf(&block.data, leftPadBytes, int(leftPadPos), int(numLeftPad), maxWriteSize)
if err != nil {
return int64(b), b, err
}
numLeftPad = int64(b)
cacheEntry.Info.Size += (int64(cacheNum) * MaxBlockSize)
}
b, writeErr := WriteToCacheBuf(&block.data, p, pos, length, maxWriteSize)
bytesWritten += b
blockLenDiff := len(block.data) - blockLen
block.size = len(block.data)
cacheEntry.Info.Size += int64(blockLenDiff)
block.dirty = true
cacheEntry.DecRefs()
return numLeftPad, bytesWritten, writeErr
}
func ReadFromCacheBlock(ctx context.Context, blockId string, name string, block *CacheBlock, p *[]byte, pos int, length int, destOffset int, maxRead int64) (int, error) {
defer func() {
if r := recover(); r != nil {
log.Printf("recovered from crash %v ", r)
log.Printf("values: %v %v %v %v %v %v", pos, length, destOffset, maxRead, p, block)
os.Exit(0)
}
}()
if pos > len(block.data) {
return 0, fmt.Errorf("reading past end of cache block, should never happen")
}
bytesWritten := 0
index := pos
for ; index < length+pos; index++ {
if int64(index) >= maxRead {
return index - pos, fmt.Errorf(MaxSizeError)
}
if index >= len(block.data) {
return bytesWritten, nil
}
destIndex := index - pos + destOffset
if destIndex >= len(*p) {
return bytesWritten, nil
}
(*p)[destIndex] = block.data[index]
bytesWritten++
}
if int64(index) >= maxRead {
return bytesWritten, fmt.Errorf(MaxSizeError)
}
return bytesWritten, nil
}
const MaxSizeError = "MaxSizeError"
func WriteToCacheBuf(buf *[]byte, p []byte, pos int, length int, maxWrite int64) (int, error) {
bytesToWrite := length
if pos > len(*buf) {
return 0, fmt.Errorf("writing to a position (%v) in the cache that doesn't exist yet, something went wrong", pos)
}
if int64(pos+bytesToWrite) > MaxBlockSize {
return 0, fmt.Errorf("writing more bytes than max block size, not allowed - length of bytes to write: %v, length of cache: %v", bytesToWrite, len(*buf))
}
for index := pos; index < bytesToWrite+pos; index++ {
if index-pos >= len(p) {
return len(p), nil
}
if int64(index) >= maxWrite {
return index - pos, fmt.Errorf(MaxSizeError)
}
curByte := p[index-pos]
if len(*buf) == index {
*buf = append(*buf, curByte)
} else {
(*buf)[index] = curByte
}
}
return bytesToWrite, nil
}
func GetCacheId(blockId string, name string) string {
return blockId + "~SEP~" + name
}
func GetValuesFromCacheId(cacheId string) (blockId string, name string) {
vals := strings.Split(cacheId, "~SEP~")
if len(vals) == 2 {
return vals[0], vals[1]
} else {
log.Println("Failure in GetValuesFromCacheId, this should never happen")
return "", ""
}
}
func GetCacheEntry(ctx context.Context, blockId string, name string) (*CacheEntry, bool) {
globalLock.Lock()
defer globalLock.Unlock()
if curCacheEntry, found := blockstoreCache[GetCacheId(blockId, name)]; found {
return curCacheEntry, true
} else {
return nil, false
}
}
func GetCacheEntryOrPopulate(ctx context.Context, blockId string, name string) (*CacheEntry, error) {
if cacheEntry, found := GetCacheEntry(ctx, blockId, name); found {
return cacheEntry, nil
} else {
log.Printf("populating cache entry\n")
_, err := Stat(ctx, blockId, name)
if err != nil {
return nil, err
}
if cacheEntry, found := GetCacheEntry(ctx, blockId, name); found {
return cacheEntry, nil
} else {
return nil, fmt.Errorf("error getting cache entry %v %v", blockId, name)
}
}
}
func SetCacheEntry(ctx context.Context, cacheId string, cacheEntry *CacheEntry) {
globalLock.Lock()
defer globalLock.Unlock()
if _, found := blockstoreCache[cacheId]; found {
return
}
blockstoreCache[cacheId] = cacheEntry
}
func DeleteCacheEntry(ctx context.Context, blockId string, name string) {
globalLock.Lock()
defer globalLock.Unlock()
delete(blockstoreCache, GetCacheId(blockId, name))
}
func GetCacheBlock(ctx context.Context, blockId string, name string, cacheNum int, pullFromDB bool) (*CacheBlock, error) {
curCacheEntry, err := GetCacheEntryOrPopulate(ctx, blockId, name)
if err != nil {
return nil, err
}
if len(curCacheEntry.DataBlocks) < cacheNum+1 {
for index := len(curCacheEntry.DataBlocks); index < cacheNum+1; index++ {
curCacheEntry.DataBlocks = append(curCacheEntry.DataBlocks, nil)
}
}
if curCacheEntry.DataBlocks[cacheNum] == nil {
var curCacheBlock *CacheBlock
if pullFromDB {
cacheData, err := GetCacheFromDB(ctx, blockId, name, 0, MaxBlockSize, int64(cacheNum))
if err != nil {
return nil, err
}
curCacheBlock = &CacheBlock{data: *cacheData, size: len(*cacheData), dirty: false}
curCacheEntry.DataBlocks[cacheNum] = curCacheBlock
} else {
curCacheBlock = &CacheBlock{data: []byte{}, size: 0, dirty: false}
curCacheEntry.DataBlocks[cacheNum] = curCacheBlock
}
return curCacheBlock, nil
} else {
return curCacheEntry.DataBlocks[cacheNum], nil
}
}
func DeepCopyFileInfo(fInfo *FileInfo) *FileInfo {
fInfoMeta := make(FileMeta)
for k, v := range fInfo.Meta {
fInfoMeta[k] = v
}
fInfoOpts := fInfo.Opts
fInfoCopy := &FileInfo{BlockId: fInfo.BlockId, Name: fInfo.Name, Size: fInfo.Size, CreatedTs: fInfo.CreatedTs, ModTs: fInfo.ModTs, Opts: fInfoOpts, Meta: fInfoMeta}
return fInfoCopy
}
func Stat(ctx context.Context, blockId string, name string) (*FileInfo, error) {
cacheEntry, found := GetCacheEntry(ctx, blockId, name)
if found {
return DeepCopyFileInfo(cacheEntry.Info), nil
}
curCacheEntry := MakeCacheEntry(nil)
curCacheEntry.Lock.Lock()
defer curCacheEntry.Lock.Unlock()
fInfo, err := GetFileInfo(ctx, blockId, name)
if err != nil {
return nil, err
}
curCacheEntry.Info = fInfo
SetCacheEntry(ctx, GetCacheId(blockId, name), curCacheEntry)
return DeepCopyFileInfo(fInfo), nil
}
func SetFlushTimeout(newTimeout time.Duration) {
flushTimeout = newTimeout
}
func GetClockString(t time.Time) string {
hour, min, sec := t.Clock()
return fmt.Sprintf("%v:%v:%v", hour, min, sec)
}
func StartFlushTimer(ctx context.Context) {
curTime := time.Now()
writeTimePassed := curTime.UnixNano() - lastWriteTime.UnixNano()
if writeTimePassed >= int64(flushTimeout) {
lastWriteTime = curTime
go func() {
time.Sleep(flushTimeout)
FlushCache(ctx)
}()
}
}
func WriteAt(ctx context.Context, blockId string, name string, p []byte, off int64) (int, error) {
return WriteAtHelper(ctx, blockId, name, p, off, true)
}
func WriteAtHelper(ctx context.Context, blockId string, name string, p []byte, off int64, flushCache bool) (int, error) {
bytesToWrite := len(p)
bytesWritten := 0
curCacheNum := int(math.Floor(float64(off) / float64(MaxBlockSize)))
numCaches := int(math.Ceil(float64(bytesToWrite) / float64(MaxBlockSize)))
cacheOffset := off - (int64(curCacheNum) * MaxBlockSize)
if (cacheOffset + int64(bytesToWrite)) > MaxBlockSize {
numCaches += 1
}
fInfo, err := Stat(ctx, blockId, name)
if err != nil {
return 0, fmt.Errorf("WriteAt err: %v", err)
}
if off > fInfo.Opts.MaxSize && fInfo.Opts.Circular {
numOver := off / fInfo.Opts.MaxSize
off = off - (numOver * fInfo.Opts.MaxSize)
}
for index := curCacheNum; index < curCacheNum+numCaches; index++ {
cacheOffset := off - (int64(index) * MaxBlockSize)
bytesToWriteToCurCache := int(math.Min(float64(bytesToWrite), float64(MaxBlockSize-cacheOffset)))
pullFromDB := true
if cacheOffset == 0 && int64(bytesToWriteToCurCache) == MaxBlockSize {
pullFromDB = false
}
_, b, err := WriteToCacheBlockNum(ctx, blockId, name, p, int(cacheOffset), bytesToWriteToCurCache, index, pullFromDB)
bytesWritten += b
bytesToWrite -= b
off += int64(b)
if err != nil {
if err.Error() == MaxSizeError {
if fInfo.Opts.Circular {
p = p[int64(b):]
b, err := WriteAtHelper(ctx, blockId, name, p, 0, false)
bytesWritten += b
if err != nil {
return bytesWritten, fmt.Errorf("write to cache error: %v", err)
}
break
}
} else {
return bytesWritten, fmt.Errorf("write to cache error: %v", err)
}
}
if len(p) == b {
break
}
p = p[int64(b):]
}
if flushCache {
StartFlushTimer(ctx)
}
return bytesWritten, nil
}
func GetAllBlockSizes(dataBlocks []*CacheBlock) (int, int) {
rtn := 0
numNil := 0
for idx, block := range dataBlocks {
if block == nil {
numNil += 1
continue
}
rtn += block.size
if block.size != len(block.data) {
log.Printf("error: block %v has incorrect block size : %v %v", idx, block.size, len(block.data))
}
}
return rtn, numNil
}
func FlushCache(ctx context.Context) error {
for _, cacheEntry := range blockstoreCache {
err := WriteFileToDB(ctx, *cacheEntry.Info)
if err != nil {
return err
}
clearEntry := true
cacheEntry.Lock.Lock()
for index, block := range cacheEntry.DataBlocks {
if block == nil || block.size == 0 {
continue
}
if !block.dirty {
clearEntry = false
continue
}
err := WriteDataBlockToDB(ctx, cacheEntry.Info.BlockId, cacheEntry.Info.Name, index, block.data)
if err != nil {
return err
}
cacheEntry.DataBlocks[index] = nil
}
cacheEntry.Lock.Unlock()
if clearEntry && cacheEntry.Refs <= 0 {
DeleteCacheEntry(ctx, cacheEntry.Info.BlockId, cacheEntry.Info.Name)
}
}
return nil
}
func ReadAt(ctx context.Context, blockId string, name string, p *[]byte, off int64) (int, error) {
bytesRead := 0
fInfo, err := Stat(ctx, blockId, name)
if err != nil {
return 0, fmt.Errorf("ReadAt err: %v", err)
}
if off > fInfo.Opts.MaxSize && fInfo.Opts.Circular {
numOver := off / fInfo.Opts.MaxSize
off = off - (numOver * fInfo.Opts.MaxSize)
}
if off > fInfo.Size {
return 0, fmt.Errorf("ReadAt error: tried to read past the end of the file")
}
endReadPos := math.Min(float64(int64(len(*p))+off), float64(fInfo.Size))
bytesToRead := int64(endReadPos) - off
curCacheNum := int(math.Floor(float64(off) / float64(MaxBlockSize)))
numCaches := int(math.Ceil(float64(bytesToRead) / float64(MaxBlockSize)))
cacheOffset := off - (int64(curCacheNum) * MaxBlockSize)
if (cacheOffset + int64(bytesToRead)) > MaxBlockSize {
numCaches += 1
}
for index := curCacheNum; index < curCacheNum+numCaches; index++ {
curCacheBlock, err := GetCacheBlock(ctx, blockId, name, index, true)
if err != nil {
return bytesRead, fmt.Errorf("error getting cache block: %v", err)
}
cacheOffset := off - (int64(index) * MaxBlockSize)
if cacheOffset < 0 {
return bytesRead, nil
}
bytesToReadFromCurCache := int(math.Min(float64(bytesToRead), float64(MaxBlockSize-cacheOffset)))
fileMaxSize := fInfo.Opts.MaxSize
maxReadSize := fileMaxSize - (int64(index) * MaxBlockSize)
b, err := ReadFromCacheBlock(ctx, blockId, name, curCacheBlock, p, int(cacheOffset), bytesToReadFromCurCache, bytesRead, maxReadSize)
if b == 0 {
log.Printf("something wrong %v %v %v %v %v %v %v %v", index, off, cacheOffset, curCacheNum, numCaches, bytesRead, bytesToRead, curCacheBlock)
cacheEntry, _ := GetCacheEntry(ctx, blockId, name)
blockSize, numNil := GetAllBlockSizes(cacheEntry.DataBlocks)
maybeDBSize := int64(numNil) * MaxBlockSize
maybeFullSize := int64(blockSize) + maybeDBSize
log.Printf("block actual sizes: %v %v %v %v %v\n", blockSize, numNil, maybeDBSize, maybeFullSize, len(cacheEntry.DataBlocks))
}
bytesRead += b
bytesToRead -= int64(b)
off += int64(b)
if err != nil {
if err.Error() == MaxSizeError {
if fInfo.Opts.Circular {
off = 0
newP := (*p)[b:]
b, err := ReadAt(ctx, blockId, name, &newP, off)
bytesRead += b
if err != nil {
return bytesRead, err
}
break
}
} else {
return bytesRead, fmt.Errorf("read from cache error: %v", err)
}
}
}
return bytesRead, nil
}
func AppendData(ctx context.Context, blockId string, name string, p []byte) (int, error) {
appendLock.Lock()
defer appendLock.Unlock()
fInfo, err := Stat(ctx, blockId, name)
if err != nil {
return 0, fmt.Errorf("append stat error: %v", err)
}
return WriteAt(ctx, blockId, name, p, fInfo.Size)
}
func DeleteFile(ctx context.Context, blockId string, name string) error {
DeleteCacheEntry(ctx, blockId, name)
err := DeleteFileFromDB(ctx, blockId, name)
return err
}
func DeleteBlock(ctx context.Context, blockId string) error {
for cacheId := range blockstoreCache {
curBlockId, name := GetValuesFromCacheId(cacheId)
if curBlockId == blockId {
err := DeleteFile(ctx, blockId, name)
if err != nil {
return fmt.Errorf("error deleting %v %v: %v", blockId, name, err)
}
}
}
err := DeleteBlockFromDB(ctx, blockId)
return err
}
func WriteFile(ctx context.Context, blockId string, name string, meta FileMeta, opts FileOptsType, data []byte) (int, error) {
MakeFile(ctx, blockId, name, meta, opts)
return AppendData(ctx, blockId, name, data)
}
func WriteMeta(ctx context.Context, blockId string, name string, meta FileMeta) error {
_, err := Stat(ctx, blockId, name)
// stat so that we can make sure cache entry is popuplated
if err != nil {
return err
}
cacheEntry, found := GetCacheEntry(ctx, blockId, name)
if !found {
return fmt.Errorf("WriteAt error: cache entry not found")
}
cacheEntry.Lock.Lock()
defer cacheEntry.Lock.Unlock()
cacheEntry.Info.Meta = meta
return nil
}
func ListFiles(ctx context.Context, blockId string) []*FileInfo {
fInfoArr, err := GetAllFilesInDBForBlockId(ctx, blockId)
if err != nil {
return nil
}
return fInfoArr
}
func ListAllFiles(ctx context.Context) []*FileInfo {
fInfoArr, err := GetAllFilesInDB(ctx)
if err != nil {
return nil
}
return fInfoArr
}
func GetAllBlockIds(ctx context.Context) []string {
rtn, err := GetAllBlockIdsInDB(ctx)
if err != nil {
return nil
}
return rtn
}