github.com/braveheart12/just@v0.8.7/configuration/ledger.go (about)

     1  /*
     2   *    Copyright 2019 Insolar Technologies
     3   *
     4   *    Licensed under the Apache License, Version 2.0 (the "License");
     5   *    you may not use this file except in compliance with the License.
     6   *    You may obtain a copy of the License at
     7   *
     8   *        http://www.apache.org/licenses/LICENSE-2.0
     9   *
    10   *    Unless required by applicable law or agreed to in writing, software
    11   *    distributed under the License is distributed on an "AS IS" BASIS,
    12   *    WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
    13   *    See the License for the specific language governing permissions and
    14   *    limitations under the License.
    15   */
    16  
    17  package configuration
    18  
    19  import (
    20  	"time"
    21  )
    22  
    23  // Storage configures Ledger's storage.
    24  type Storage struct {
    25  	// DataDirectory is a directory where database's files live.
    26  	DataDirectory string
    27  	// TxRetriesOnConflict defines how many retries on transaction conflicts
    28  	// storage update methods should do.
    29  	TxRetriesOnConflict int
    30  }
    31  
    32  // PulseManager holds configuration for PulseManager.
    33  type PulseManager struct {
    34  	// HeavySyncEnabled enables replication to heavy (could be disabled for testing purposes)
    35  	HeavySyncEnabled bool
    36  	// HeavySyncMessageLimit soft limit of single message for replication to heavy.
    37  	HeavySyncMessageLimit int
    38  	// Backoff configures retry backoff algorithm for Heavy Sync
    39  	HeavyBackoff Backoff
    40  	// SplitThreshold is a drop size threshold in bytes to perform split.
    41  	SplitThreshold uint64
    42  }
    43  
    44  // Backoff configures retry backoff algorithm
    45  type Backoff struct {
    46  	Factor float64
    47  	// Jitter eases contention by randomizing backoff steps
    48  	Jitter bool
    49  	// Min and Max are the minimum and maximum values of the counter
    50  	Min, Max time.Duration
    51  }
    52  
    53  // RecentStorage holds configuration for RecentStorage
    54  type RecentStorage struct {
    55  	// Default TTL is a value of default ttl for redirects
    56  	DefaultTTL int
    57  }
    58  
    59  // Exporter holds configuration of Exporter
    60  type Exporter struct {
    61  	// ExportLag is lag in second before we start to export pulse
    62  	ExportLag uint32
    63  }
    64  
    65  // Ledger holds configuration for ledger.
    66  type Ledger struct {
    67  	// Storage defines storage configuration.
    68  	Storage Storage
    69  	// PulseManager holds configuration for PulseManager.
    70  	PulseManager PulseManager
    71  	// RecentStorage holds configuration for RecentStorage
    72  	RecentStorage RecentStorage
    73  
    74  	// common/sharable values:
    75  
    76  	// LightChainLimit is maximum pulse difference (NOT number of pulses)
    77  	// between current and the latest replicated on heavy.
    78  	//
    79  	// IMPORTANT: It should be the same on ALL nodes.
    80  	LightChainLimit int
    81  
    82  	// JetSizesHistoryDepth holds maximum number of drop sizes
    83  	JetSizesHistoryDepth int
    84  
    85  	// Exporter holds configuration of Exporter
    86  	Exporter Exporter
    87  
    88  	// PendingRequestsLimit holds a number of pending requests, what can be stored in the system
    89  	// before they are declined
    90  	PendingRequestsLimit int
    91  }
    92  
    93  // NewLedger creates new default Ledger configuration.
    94  func NewLedger() Ledger {
    95  	return Ledger{
    96  		Storage: Storage{
    97  			DataDirectory:       "./data",
    98  			TxRetriesOnConflict: 3,
    99  		},
   100  
   101  		PulseManager: PulseManager{
   102  			HeavySyncEnabled:      true,
   103  			HeavySyncMessageLimit: 1 << 20, // 1Mb
   104  			HeavyBackoff: Backoff{
   105  				Jitter: true,
   106  				Min:    200 * time.Millisecond,
   107  				Max:    2 * time.Second,
   108  				Factor: 2,
   109  			},
   110  			SplitThreshold: 10 * 100, // 10 megabytes.
   111  		},
   112  
   113  		RecentStorage: RecentStorage{
   114  			DefaultTTL: 10,
   115  		},
   116  
   117  		LightChainLimit: 5, // 5 pulses
   118  
   119  		JetSizesHistoryDepth: 10,
   120  
   121  		Exporter: Exporter{
   122  			ExportLag: 40, // 40 seconds
   123  		},
   124  
   125  		PendingRequestsLimit: 1000,
   126  	}
   127  }