github.com/klaytn/klaytn@v1.12.1/storage/database/dynamodb_readonly.go (about)

     1  // Copyright 2020 The klaytn Authors
     2  // This file is part of the klaytn library.
     3  //
     4  // The klaytn library is free software: you can redistribute it and/or modify
     5  // it under the terms of the GNU Lesser General Public License as published by
     6  // the Free Software Foundation, either version 3 of the License, or
     7  // (at your option) any later version.
     8  //
     9  // The klaytn library is distributed in the hope that it will be useful,
    10  // but WITHOUT ANY WARRANTY; without even the implied warranty of
    11  // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
    12  // GNU Lesser General Public License for more details.
    13  //
    14  // You should have received a copy of the GNU Lesser General Public License
    15  // along with the klaytn library. If not, see <http://www.gnu.org/licenses/>.
    16  //
    17  // Database implementation of AWS DynamoDB READ ONLY.
    18  // Calling put, delete, batch put and batch write does nothing and returns no error.
    19  // Other functions such as get and has will call functions in dynamoDB.
    20  //
    21  // [WARN] Using this DB may cause pricing in your AWS account.
    22  // [WARN] DynamoDB creates both Dynamo DB table and S3 bucket.
    23  //
    24  // You need to set AWS credentials to access to dynamoDB.
    25  //    $ export AWS_ACCESS_KEY_ID=YOUR_ACCESS_KEY
    26  //    $ export AWS_SECRET_ACCESS_KEY=YOUR_SECRET
    27  
    28  package database
    29  
    30  // dynamoDBReadOnly uses dynamoDB.
    31  // Calling put, delete, batch put and batch write does nothing and returns no error.
    32  // Other functions such as get and has will call functions in dynamoDB.
    33  type dynamoDBReadOnly struct {
    34  	dynamoDB
    35  }
    36  
    37  // newDynamoDBReadOnly creates dynamoDBReadOnly. This uses dynamoDB to create dynamoDBReadOnly.
    38  func newDynamoDBReadOnly(config *DynamoDBConfig) (*dynamoDBReadOnly, error) {
    39  	config.ReadOnly = true
    40  	dynamo, err := newDynamoDB(config)
    41  	if err != nil {
    42  		return nil, err
    43  	}
    44  	dynamo.logger.Warn("Read only flag is set for dynamoDB. Check for billing method and capacity.")
    45  	return &dynamoDBReadOnly{*dynamo}, nil
    46  }
    47  
    48  func (dynamo *dynamoDBReadOnly) Put(key []byte, val []byte) error {
    49  	return nil
    50  }
    51  
    52  func (dynamo *dynamoDBReadOnly) Delete(key []byte) error {
    53  	return nil
    54  }
    55  
    56  func (dynamo *dynamoDBReadOnly) Close() {
    57  }
    58  
    59  func (dynamo *dynamoDBReadOnly) NewBatch() Batch {
    60  	return &emptyBatch{}
    61  }
    62  
    63  type emptyBatch struct{}
    64  
    65  func (batch *emptyBatch) Put(key, val []byte) error {
    66  	return nil
    67  }
    68  
    69  func (batch *emptyBatch) Delete(key []byte) error {
    70  	return nil
    71  }
    72  
    73  func (batch *emptyBatch) Write() error {
    74  	return nil
    75  }
    76  
    77  func (batch *emptyBatch) ValueSize() int {
    78  	return 0
    79  }
    80  
    81  func (batch *emptyBatch) Reset() {
    82  }
    83  
    84  func (batch *emptyBatch) Release() {
    85  }
    86  
    87  func (batch *emptyBatch) Replay(w KeyValueWriter) error {
    88  	return nil
    89  }