github.com/rohankumardubey/aresdb@v0.0.2-0.20190517170215-e54e3ca06b9c/diskstore/diskstore.go (about)

     1  //  Copyright (c) 2017-2018 Uber Technologies, Inc.
     2  //
     3  // Licensed under the Apache License, Version 2.0 (the "License");
     4  // you may not use this file except in compliance with the License.
     5  // You may obtain a copy of the License at
     6  //
     7  //     http://www.apache.org/licenses/LICENSE-2.0
     8  //
     9  // Unless required by applicable law or agreed to in writing, software
    10  // distributed under the License is distributed on an "AS IS" BASIS,
    11  // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
    12  // See the License for the specific language governing permissions and
    13  // limitations under the License.
    14  
    15  package diskstore
    16  
    17  import (
    18  	"io"
    19  
    20  	"github.com/uber/aresdb/utils"
    21  )
    22  
    23  // DiskStore defines the interface for reading/writing redo logs, snapshot files, and archived vector party files.
    24  type DiskStore interface {
    25  	// Table shard level operation
    26  
    27  	// Completely wipe out a table shard.
    28  	DeleteTableShard(table string, shard int) error
    29  
    30  	// Redo logs.
    31  
    32  	// Returns the file creation unix time in second for each log file as a sorted slice.
    33  	ListLogFiles(table string, shard int) ([]int64, error)
    34  	// Opens the specified log file for replay.
    35  	OpenLogFileForReplay(table string, shard int, creationTime int64) (utils.ReaderSeekerCloser, error)
    36  	// Opens/creates the specified log file for append.
    37  	OpenLogFileForAppend(table string, shard int, creationTime int64) (io.WriteCloser, error)
    38  	// Deletes the specified log file.
    39  	DeleteLogFile(table string, shard int, creationTime int64) error
    40  	// Truncate Redolog to drop the last incomplete/corrupted upsert batch.
    41  	TruncateLogFile(table string, shard int, creationTime int64, offset int64) error
    42  
    43  	// Snapshot files.
    44  	// Snapshots are stored in following format:
    45  	// {root_path}/data/{table_name}_{shard_id}/snapshots/
    46  	// 	 -- {redo_log1}_{offset1}
    47  	//     -- {batchID1}
    48  	//        -- {column1}.data
    49  	//        -- {column2}.data
    50  	//     -- {batchID2}
    51  	//        -- {column1}.data
    52  	//        -- {column2}.data
    53  	//
    54  	// 	 -- {redo_log2}_{offset2}
    55  	//     -- {batchID1}
    56  	//        -- {column1}.data
    57  	//        -- {column2}.data
    58  	//     -- {batchID2}
    59  	//        -- {column1}.data
    60  	//        -- {column2}.data
    61  	// For all following snapshot methods, a {redo_log}_{offset} specifies the snapshot version.
    62  
    63  	// Returns the batch directories under a specific snapshot directory.
    64  	ListSnapshotBatches(table string, shard int,
    65  		redoLogFile int64, offset uint32) ([]int, error)
    66  
    67  	// Returns the vector party files under a specific snapshot batch directory.
    68  	// the return value is sorted
    69  	ListSnapshotVectorPartyFiles(table string, shard int,
    70  		redoLogFile int64, offset uint32, batchID int) ([]int, error)
    71  
    72  	// Opens the snapshot vector party file for read.
    73  	OpenSnapshotVectorPartyFileForRead(table string, shard int,
    74  		redoLogFile int64, offset uint32, batchID int, columnID int) (io.ReadCloser, error)
    75  	// Creates/truncates the snapshot column file for write.
    76  
    77  	OpenSnapshotVectorPartyFileForWrite(table string, shard int,
    78  		redoLogFile int64, offset uint32, batchID int, columnID int) (io.WriteCloser, error)
    79  	// Deletes snapshot files **older than** the specified version.
    80  	DeleteSnapshot(table string, shard int, redoLogFile int64, offset uint32) error
    81  
    82  	// Archived vector party files.
    83  
    84  	// Opens the vector party file at the specified batchVersion for read.
    85  	OpenVectorPartyFileForRead(table string, column, shard, batchID int, batchVersion uint32,
    86  		seqNum uint32) (io.ReadCloser, error)
    87  	// Creates/truncates the vector party file at the specified batchVersion for write.
    88  	OpenVectorPartyFileForWrite(table string, column, shard, batchID int, batchVersion uint32,
    89  		seqNum uint32) (io.WriteCloser, error)
    90  	// Deletes all old batches with the specified batchID that have version lower than or equal to the specified batch
    91  	// version. All columns of those batches will be deleted.
    92  	DeleteBatchVersions(table string, shard, batchID int, batchVersion uint32, seqNum uint32) error
    93  	// Deletes all batches within range [batchIDStart, batchIDEnd)
    94  	DeleteBatches(table string, shard, batchIDStart, batchIDEnd int) (int, error)
    95  	// Deletes all batches of the specified column.
    96  	DeleteColumn(table string, column, shard int) error
    97  }