github.com/m3db/m3@v1.5.0/src/dbnode/client/consistency_level.go (about) 1 // Copyright (c) 2018 Uber Technologies, Inc. 2 // 3 // Permission is hereby granted, free of charge, to any person obtaining a copy 4 // of this software and associated documentation files (the "Software"), to deal 5 // in the Software without restriction, including without limitation the rights 6 // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 7 // copies of the Software, and to permit persons to whom the Software is 8 // furnished to do so, subject to the following conditions: 9 // 10 // The above copyright notice and this permission notice shall be included in 11 // all copies or substantial portions of the Software. 12 // 13 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 14 // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 15 // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 16 // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 17 // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 18 // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 19 // THE SOFTWARE. 20 21 package client 22 23 import ( 24 "github.com/m3db/m3/src/dbnode/topology" 25 ) 26 27 // runtimeReadConsistencyLevel is a queryable value for a 28 // read consistency level, this supports it being able to change 29 // dynamically or it can be just static if not required to be changed 30 // during an operation. 31 type runtimeReadConsistencyLevel interface { 32 value() topology.ReadConsistencyLevel 33 } 34 35 type staticRuntimeReadConsistencyLevel struct { 36 val topology.ReadConsistencyLevel 37 } 38 39 func newStaticRuntimeReadConsistencyLevel( 40 value topology.ReadConsistencyLevel, 41 ) runtimeReadConsistencyLevel { 42 return staticRuntimeReadConsistencyLevel{val: value} 43 } 44 45 func (l staticRuntimeReadConsistencyLevel) value() topology.ReadConsistencyLevel { 46 return l.val 47 } 48 49 // nolint: unused 50 type sessionReadRuntimeReadConsistencyLevel struct { 51 s *session 52 } 53 54 // nolint: unused 55 func newSessionReadRuntimeReadConsistencyLevel( 56 s *session, 57 ) runtimeReadConsistencyLevel { 58 return sessionReadRuntimeReadConsistencyLevel{s: s} 59 } 60 61 func (l sessionReadRuntimeReadConsistencyLevel) value() topology.ReadConsistencyLevel { 62 l.s.state.RLock() 63 value := l.s.state.readLevel 64 l.s.state.RUnlock() 65 return value 66 } 67 68 type sessionBootstrapRuntimeReadConsistencyLevel struct { 69 s *session 70 } 71 72 func newSessionBootstrapRuntimeReadConsistencyLevel( 73 s *session, 74 ) runtimeReadConsistencyLevel { 75 return sessionBootstrapRuntimeReadConsistencyLevel{s: s} 76 } 77 78 func (l sessionBootstrapRuntimeReadConsistencyLevel) value() topology.ReadConsistencyLevel { 79 l.s.state.RLock() 80 value := l.s.state.bootstrapLevel 81 l.s.state.RUnlock() 82 return value 83 }