Skip to content
This repository was archived by the owner on May 20, 2025. It is now read-only.

Commit 7c40784

Browse files
authored
use get_pinned_cf when possible (#1254)
1 parent 1d487c5 commit 7c40784

File tree

4 files changed

+47
-44
lines changed

4 files changed

+47
-44
lines changed

bee-network/bee-autopeering/src/peer/stores/rocksdb.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -99,18 +99,18 @@ impl PeerStore for RocksDbPeerStore {
9999

100100
fn contains(&self, peer_id: &PeerId) -> Result<bool, Self::Error> {
101101
let cf = self.open_cf(ACTIVE_PEERS_CF);
102-
if self.db.get_cf(&cf, peer_id)?.is_some() {
102+
if self.db.get_pinned_cf(&cf, peer_id)?.is_some() {
103103
Ok(true)
104104
} else {
105105
let cf = self.open_cf(REPLACEMENTS_CF);
106-
Ok(self.db.get_cf(&cf, peer_id)?.is_some())
106+
Ok(self.db.get_pinned_cf(&cf, peer_id)?.is_some())
107107
}
108108
}
109109

110110
fn fetch_active(&self, peer_id: &PeerId) -> Result<Option<ActivePeer>, Self::Error> {
111111
let cf = self.open_cf(ACTIVE_PEERS_CF);
112112

113-
Ok(self.db.get_cf(&cf, peer_id)?.map(|b| ActivePeer::from_bytes(&b)))
113+
Ok(self.db.get_pinned_cf(&cf, peer_id)?.map(|b| ActivePeer::from_bytes(&b)))
114114
}
115115

116116
fn fetch_all_active(&self) -> Result<Vec<ActivePeer>, Self::Error> {

bee-storage/bee-storage-rocksdb/src/access/exist.rs

Lines changed: 20 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ impl Exist<MessageId, Message> for Storage {
2727
fn exist(&self, message_id: &MessageId) -> Result<bool, <Self as StorageBackend>::Error> {
2828
Ok(self
2929
.inner
30-
.get_cf(self.cf_handle(CF_MESSAGE_ID_TO_MESSAGE)?, message_id)?
30+
.get_pinned_cf(self.cf_handle(CF_MESSAGE_ID_TO_MESSAGE)?, message_id)?
3131
.is_some())
3232
}
3333
}
@@ -38,7 +38,7 @@ impl Exist<MessageId, MessageMetadata> for Storage {
3838

3939
let exists = self
4040
.inner
41-
.get_cf(self.cf_handle(CF_MESSAGE_ID_TO_METADATA)?, message_id)?
41+
.get_pinned_cf(self.cf_handle(CF_MESSAGE_ID_TO_METADATA)?, message_id)?
4242
.is_some();
4343

4444
drop(guard);
@@ -54,7 +54,7 @@ impl Exist<(MessageId, MessageId), ()> for Storage {
5454

5555
Ok(self
5656
.inner
57-
.get_cf(self.cf_handle(CF_MESSAGE_ID_TO_MESSAGE_ID)?, key)?
57+
.get_pinned_cf(self.cf_handle(CF_MESSAGE_ID_TO_MESSAGE_ID)?, key)?
5858
.is_some())
5959
}
6060
}
@@ -66,7 +66,7 @@ impl Exist<(PaddedIndex, MessageId), ()> for Storage {
6666

6767
Ok(self
6868
.inner
69-
.get_cf(self.cf_handle(CF_INDEX_TO_MESSAGE_ID)?, key)?
69+
.get_pinned_cf(self.cf_handle(CF_INDEX_TO_MESSAGE_ID)?, key)?
7070
.is_some())
7171
}
7272
}
@@ -75,7 +75,7 @@ impl Exist<OutputId, CreatedOutput> for Storage {
7575
fn exist(&self, output_id: &OutputId) -> Result<bool, <Self as StorageBackend>::Error> {
7676
Ok(self
7777
.inner
78-
.get_cf(self.cf_handle(CF_OUTPUT_ID_TO_CREATED_OUTPUT)?, output_id.pack_new())?
78+
.get_pinned_cf(self.cf_handle(CF_OUTPUT_ID_TO_CREATED_OUTPUT)?, output_id.pack_new())?
7979
.is_some())
8080
}
8181
}
@@ -84,7 +84,7 @@ impl Exist<OutputId, ConsumedOutput> for Storage {
8484
fn exist(&self, output_id: &OutputId) -> Result<bool, <Self as StorageBackend>::Error> {
8585
Ok(self
8686
.inner
87-
.get_cf(self.cf_handle(CF_OUTPUT_ID_TO_CONSUMED_OUTPUT)?, output_id.pack_new())?
87+
.get_pinned_cf(self.cf_handle(CF_OUTPUT_ID_TO_CONSUMED_OUTPUT)?, output_id.pack_new())?
8888
.is_some())
8989
}
9090
}
@@ -93,7 +93,7 @@ impl Exist<Unspent, ()> for Storage {
9393
fn exist(&self, unspent: &Unspent) -> Result<bool, <Self as StorageBackend>::Error> {
9494
Ok(self
9595
.inner
96-
.get_cf(self.cf_handle(CF_OUTPUT_ID_UNSPENT)?, unspent.pack_new())?
96+
.get_pinned_cf(self.cf_handle(CF_OUTPUT_ID_UNSPENT)?, unspent.pack_new())?
9797
.is_some())
9898
}
9999
}
@@ -108,22 +108,25 @@ impl Exist<(Ed25519Address, OutputId), ()> for Storage {
108108

109109
Ok(self
110110
.inner
111-
.get_cf(self.cf_handle(CF_ED25519_ADDRESS_TO_OUTPUT_ID)?, key)?
111+
.get_pinned_cf(self.cf_handle(CF_ED25519_ADDRESS_TO_OUTPUT_ID)?, key)?
112112
.is_some())
113113
}
114114
}
115115

116116
impl Exist<(), LedgerIndex> for Storage {
117117
fn exist(&self, (): &()) -> Result<bool, <Self as StorageBackend>::Error> {
118-
Ok(self.inner.get_cf(self.cf_handle(CF_LEDGER_INDEX)?, [0x00u8])?.is_some())
118+
Ok(self
119+
.inner
120+
.get_pinned_cf(self.cf_handle(CF_LEDGER_INDEX)?, [0x00u8])?
121+
.is_some())
119122
}
120123
}
121124

122125
impl Exist<MilestoneIndex, Milestone> for Storage {
123126
fn exist(&self, index: &MilestoneIndex) -> Result<bool, <Self as StorageBackend>::Error> {
124127
Ok(self
125128
.inner
126-
.get_cf(self.cf_handle(CF_MILESTONE_INDEX_TO_MILESTONE)?, index.pack_new())?
129+
.get_pinned_cf(self.cf_handle(CF_MILESTONE_INDEX_TO_MILESTONE)?, index.pack_new())?
127130
.is_some())
128131
}
129132
}
@@ -132,7 +135,7 @@ impl Exist<(), SnapshotInfo> for Storage {
132135
fn exist(&self, (): &()) -> Result<bool, <Self as StorageBackend>::Error> {
133136
Ok(self
134137
.inner
135-
.get_cf(self.cf_handle(CF_SNAPSHOT_INFO)?, [0x00u8])?
138+
.get_pinned_cf(self.cf_handle(CF_SNAPSHOT_INFO)?, [0x00u8])?
136139
.is_some())
137140
}
138141
}
@@ -141,7 +144,7 @@ impl Exist<SolidEntryPoint, MilestoneIndex> for Storage {
141144
fn exist(&self, sep: &SolidEntryPoint) -> Result<bool, <Self as StorageBackend>::Error> {
142145
Ok(self
143146
.inner
144-
.get_cf(self.cf_handle(CF_SOLID_ENTRY_POINT_TO_MILESTONE_INDEX)?, sep.pack_new())?
147+
.get_pinned_cf(self.cf_handle(CF_SOLID_ENTRY_POINT_TO_MILESTONE_INDEX)?, sep.pack_new())?
145148
.is_some())
146149
}
147150
}
@@ -150,7 +153,7 @@ impl Exist<MilestoneIndex, OutputDiff> for Storage {
150153
fn exist(&self, index: &MilestoneIndex) -> Result<bool, <Self as StorageBackend>::Error> {
151154
Ok(self
152155
.inner
153-
.get_cf(self.cf_handle(CF_MILESTONE_INDEX_TO_OUTPUT_DIFF)?, index.pack_new())?
156+
.get_pinned_cf(self.cf_handle(CF_MILESTONE_INDEX_TO_OUTPUT_DIFF)?, index.pack_new())?
154157
.is_some())
155158
}
156159
}
@@ -159,7 +162,7 @@ impl Exist<Address, Balance> for Storage {
159162
fn exist(&self, address: &Address) -> Result<bool, <Self as StorageBackend>::Error> {
160163
Ok(self
161164
.inner
162-
.get_cf(self.cf_handle(CF_ADDRESS_TO_BALANCE)?, address.pack_new())?
165+
.get_pinned_cf(self.cf_handle(CF_ADDRESS_TO_BALANCE)?, address.pack_new())?
163166
.is_some())
164167
}
165168
}
@@ -174,7 +177,7 @@ impl Exist<(MilestoneIndex, UnreferencedMessage), ()> for Storage {
174177

175178
Ok(self
176179
.inner
177-
.get_cf(self.cf_handle(CF_MILESTONE_INDEX_TO_UNREFERENCED_MESSAGE)?, key)?
180+
.get_pinned_cf(self.cf_handle(CF_MILESTONE_INDEX_TO_UNREFERENCED_MESSAGE)?, key)?
178181
.is_some())
179182
}
180183
}
@@ -186,7 +189,7 @@ impl Exist<(MilestoneIndex, Receipt), ()> for Storage {
186189

187190
Ok(self
188191
.inner
189-
.get_cf(self.cf_handle(CF_MILESTONE_INDEX_TO_RECEIPT)?, key)?
192+
.get_pinned_cf(self.cf_handle(CF_MILESTONE_INDEX_TO_RECEIPT)?, key)?
190193
.is_some())
191194
}
192195
}
@@ -198,7 +201,7 @@ impl Exist<(bool, TreasuryOutput), ()> for Storage {
198201

199202
Ok(self
200203
.inner
201-
.get_cf(self.cf_handle(CF_SPENT_TO_TREASURY_OUTPUT)?, key)?
204+
.get_pinned_cf(self.cf_handle(CF_SPENT_TO_TREASURY_OUTPUT)?, key)?
202205
.is_some())
203206
}
204207
}

bee-storage/bee-storage-rocksdb/src/access/fetch.rs

Lines changed: 22 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -27,19 +27,19 @@ impl Fetch<u8, System> for Storage {
2727
fn fetch(&self, key: &u8) -> Result<Option<System>, <Self as StorageBackend>::Error> {
2828
Ok(self
2929
.inner
30-
.get_cf(self.cf_handle(CF_SYSTEM)?, [*key])?
30+
.get_pinned_cf(self.cf_handle(CF_SYSTEM)?, [*key])?
3131
// Unpacking from storage is fine.
32-
.map(|v| System::unpack_unchecked(&mut v.as_slice()).unwrap()))
32+
.map(|v| System::unpack_unchecked(&mut &*v).unwrap()))
3333
}
3434
}
3535

3636
impl Fetch<MessageId, Message> for Storage {
3737
fn fetch(&self, message_id: &MessageId) -> Result<Option<Message>, <Self as StorageBackend>::Error> {
3838
Ok(self
3939
.inner
40-
.get_cf(self.cf_handle(CF_MESSAGE_ID_TO_MESSAGE)?, message_id)?
40+
.get_pinned_cf(self.cf_handle(CF_MESSAGE_ID_TO_MESSAGE)?, message_id)?
4141
// Unpacking from storage is fine.
42-
.map(|v| Message::unpack_unchecked(&mut v.as_slice()).unwrap()))
42+
.map(|v| Message::unpack_unchecked(&mut &*v).unwrap()))
4343
}
4444
}
4545

@@ -49,9 +49,9 @@ impl Fetch<MessageId, MessageMetadata> for Storage {
4949

5050
let metadata = self
5151
.inner
52-
.get_cf(self.cf_handle(CF_MESSAGE_ID_TO_METADATA)?, message_id)?
52+
.get_pinned_cf(self.cf_handle(CF_MESSAGE_ID_TO_METADATA)?, message_id)?
5353
// Unpacking from storage is fine.
54-
.map(|v| MessageMetadata::unpack_unchecked(&mut v.as_slice()).unwrap());
54+
.map(|v| MessageMetadata::unpack_unchecked(&mut &*v).unwrap());
5555

5656
drop(guard);
5757

@@ -97,19 +97,19 @@ impl Fetch<OutputId, CreatedOutput> for Storage {
9797
fn fetch(&self, output_id: &OutputId) -> Result<Option<CreatedOutput>, <Self as StorageBackend>::Error> {
9898
Ok(self
9999
.inner
100-
.get_cf(self.cf_handle(CF_OUTPUT_ID_TO_CREATED_OUTPUT)?, output_id.pack_new())?
100+
.get_pinned_cf(self.cf_handle(CF_OUTPUT_ID_TO_CREATED_OUTPUT)?, output_id.pack_new())?
101101
// Unpacking from storage is fine.
102-
.map(|v| CreatedOutput::unpack_unchecked(&mut v.as_slice()).unwrap()))
102+
.map(|v| CreatedOutput::unpack_unchecked(&mut &*v).unwrap()))
103103
}
104104
}
105105

106106
impl Fetch<OutputId, ConsumedOutput> for Storage {
107107
fn fetch(&self, output_id: &OutputId) -> Result<Option<ConsumedOutput>, <Self as StorageBackend>::Error> {
108108
Ok(self
109109
.inner
110-
.get_cf(self.cf_handle(CF_OUTPUT_ID_TO_CONSUMED_OUTPUT)?, output_id.pack_new())?
110+
.get_pinned_cf(self.cf_handle(CF_OUTPUT_ID_TO_CONSUMED_OUTPUT)?, output_id.pack_new())?
111111
// Unpacking from storage is fine.
112-
.map(|v| ConsumedOutput::unpack_unchecked(&mut v.as_slice()).unwrap()))
112+
.map(|v| ConsumedOutput::unpack_unchecked(&mut &*v).unwrap()))
113113
}
114114
}
115115

@@ -133,59 +133,59 @@ impl Fetch<(), LedgerIndex> for Storage {
133133
fn fetch(&self, (): &()) -> Result<Option<LedgerIndex>, <Self as StorageBackend>::Error> {
134134
Ok(self
135135
.inner
136-
.get_cf(self.cf_handle(CF_LEDGER_INDEX)?, [0x00u8])?
136+
.get_pinned_cf(self.cf_handle(CF_LEDGER_INDEX)?, [0x00u8])?
137137
// Unpacking from storage is fine.
138-
.map(|v| LedgerIndex::unpack_unchecked(&mut v.as_slice()).unwrap()))
138+
.map(|v| LedgerIndex::unpack_unchecked(&mut &*v).unwrap()))
139139
}
140140
}
141141

142142
impl Fetch<MilestoneIndex, Milestone> for Storage {
143143
fn fetch(&self, index: &MilestoneIndex) -> Result<Option<Milestone>, <Self as StorageBackend>::Error> {
144144
Ok(self
145145
.inner
146-
.get_cf(self.cf_handle(CF_MILESTONE_INDEX_TO_MILESTONE)?, index.pack_new())?
146+
.get_pinned_cf(self.cf_handle(CF_MILESTONE_INDEX_TO_MILESTONE)?, index.pack_new())?
147147
// Unpacking from storage is fine.
148-
.map(|v| Milestone::unpack_unchecked(&mut v.as_slice()).unwrap()))
148+
.map(|v| Milestone::unpack_unchecked(&mut &*v).unwrap()))
149149
}
150150
}
151151

152152
impl Fetch<(), SnapshotInfo> for Storage {
153153
fn fetch(&self, (): &()) -> Result<Option<SnapshotInfo>, <Self as StorageBackend>::Error> {
154154
Ok(self
155155
.inner
156-
.get_cf(self.cf_handle(CF_SNAPSHOT_INFO)?, [0x00u8])?
156+
.get_pinned_cf(self.cf_handle(CF_SNAPSHOT_INFO)?, [0x00u8])?
157157
// Unpacking from storage is fine.
158-
.map(|v| SnapshotInfo::unpack_unchecked(&mut v.as_slice()).unwrap()))
158+
.map(|v| SnapshotInfo::unpack_unchecked(&mut &*v).unwrap()))
159159
}
160160
}
161161

162162
impl Fetch<SolidEntryPoint, MilestoneIndex> for Storage {
163163
fn fetch(&self, sep: &SolidEntryPoint) -> Result<Option<MilestoneIndex>, <Self as StorageBackend>::Error> {
164164
Ok(self
165165
.inner
166-
.get_cf(self.cf_handle(CF_SOLID_ENTRY_POINT_TO_MILESTONE_INDEX)?, sep.as_ref())?
166+
.get_pinned_cf(self.cf_handle(CF_SOLID_ENTRY_POINT_TO_MILESTONE_INDEX)?, sep.as_ref())?
167167
// Unpacking from storage is fine.
168-
.map(|v| MilestoneIndex::unpack_unchecked(&mut v.as_slice()).unwrap()))
168+
.map(|v| MilestoneIndex::unpack_unchecked(&mut &*v).unwrap()))
169169
}
170170
}
171171

172172
impl Fetch<MilestoneIndex, OutputDiff> for Storage {
173173
fn fetch(&self, index: &MilestoneIndex) -> Result<Option<OutputDiff>, <Self as StorageBackend>::Error> {
174174
Ok(self
175175
.inner
176-
.get_cf(self.cf_handle(CF_MILESTONE_INDEX_TO_OUTPUT_DIFF)?, index.pack_new())?
176+
.get_pinned_cf(self.cf_handle(CF_MILESTONE_INDEX_TO_OUTPUT_DIFF)?, index.pack_new())?
177177
// Unpacking from storage is fine.
178-
.map(|v| OutputDiff::unpack_unchecked(&mut v.as_slice()).unwrap()))
178+
.map(|v| OutputDiff::unpack_unchecked(&mut &*v).unwrap()))
179179
}
180180
}
181181

182182
impl Fetch<Address, Balance> for Storage {
183183
fn fetch(&self, address: &Address) -> Result<Option<Balance>, <Self as StorageBackend>::Error> {
184184
Ok(self
185185
.inner
186-
.get_cf(self.cf_handle(CF_ADDRESS_TO_BALANCE)?, address.pack_new())?
186+
.get_pinned_cf(self.cf_handle(CF_ADDRESS_TO_BALANCE)?, address.pack_new())?
187187
// Unpacking from storage is fine.
188-
.map(|v| Balance::unpack_unchecked(&mut v.as_slice()).unwrap()))
188+
.map(|v| Balance::unpack_unchecked(&mut &*v).unwrap()))
189189
}
190190
}
191191

bee-storage/bee-storage-rocksdb/src/access/update.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,9 +14,9 @@ impl Update<MessageId, MessageMetadata> for Storage {
1414

1515
let guard = self.locks.message_id_to_metadata.write();
1616

17-
if let Some(v) = self.inner.get_cf(cf_handle, message_id)? {
17+
if let Some(v) = self.inner.get_pinned_cf(cf_handle, message_id)? {
1818
// Unpacking from storage is fine.
19-
let mut metadata = MessageMetadata::unpack_unchecked(&mut v.as_slice()).unwrap();
19+
let mut metadata = MessageMetadata::unpack_unchecked(&mut &*v).unwrap();
2020

2121
f(&mut metadata);
2222

0 commit comments

Comments
 (0)