1
1
use crate :: config:: Config ;
2
2
use serde:: Deserialize ;
3
3
use std:: error:: Error ;
4
+ use tracing:: { debug, info} ;
4
5
5
6
mod pooled;
6
7
pub mod postgres;
@@ -74,10 +75,12 @@ impl KVStorage {
74
75
pub async fn new ( config : & Config ) -> Result < Box < Self > , Box < dyn Error > > {
75
76
match config. kvstorage_type {
76
77
KVStorageType :: Postgres => {
78
+ info ! ( "Using Postgres as KV storage" ) ;
77
79
let storage = postgres:: Postgres :: new ( config) . await ?;
78
80
Ok ( Box :: new ( KVStorage :: Postgres ( * storage) ) )
79
81
}
80
82
KVStorageType :: SQLite => {
83
+ info ! ( "Using SQLite as KV storage" ) ;
81
84
let storage = sqlite:: SQLite :: new ( config) . await ?;
82
85
Ok ( Box :: new ( KVStorage :: SQLite ( * storage) ) )
83
86
}
@@ -92,6 +95,7 @@ impl KVStorage {
92
95
}
93
96
94
97
pub async fn get_ref_count ( & mut self , bucket : & str , hash : & str ) -> Result < i32 , Box < dyn Error > > {
98
+ debug ! ( "Getting ref count for bucket: {}, hash: {}" , bucket, hash) ;
95
99
match self {
96
100
KVStorage :: Postgres ( storage) => storage. get_ref_count ( bucket, hash) . await ,
97
101
KVStorage :: SQLite ( storage) => storage. get_ref_count ( bucket, hash) . await ,
@@ -104,6 +108,10 @@ impl KVStorage {
104
108
hash : & str ,
105
109
ref_cnt : i32 ,
106
110
) -> Result < ( ) , Box < dyn Error > > {
111
+ debug ! (
112
+ "Setting ref count for bucket: {}, hash: {} to {}" ,
113
+ bucket, hash, ref_cnt
114
+ ) ;
107
115
match self {
108
116
KVStorage :: Postgres ( storage) => storage. set_ref_count ( bucket, hash, ref_cnt) . await ,
109
117
KVStorage :: SQLite ( storage) => storage. set_ref_count ( bucket, hash, ref_cnt) . await ,
@@ -115,6 +123,7 @@ impl KVStorage {
115
123
bucket : & str ,
116
124
hash : & str ,
117
125
) -> Result < ( ) , Box < dyn Error > > {
126
+ debug ! ( "Incrementing ref count for bucket: {}, hash: {}" , bucket, hash) ;
118
127
match self {
119
128
KVStorage :: Postgres ( storage) => storage. increment_ref_count ( bucket, hash) . await ,
120
129
KVStorage :: SQLite ( storage) => storage. increment_ref_count ( bucket, hash) . await ,
@@ -126,13 +135,15 @@ impl KVStorage {
126
135
bucket : & str ,
127
136
hash : & str ,
128
137
) -> Result < ( ) , Box < dyn Error > > {
138
+ debug ! ( "Decrementing ref count for bucket: {}, hash: {}" , bucket, hash) ;
129
139
match self {
130
140
KVStorage :: Postgres ( storage) => storage. decrement_ref_count ( bucket, hash) . await ,
131
141
KVStorage :: SQLite ( storage) => storage. decrement_ref_count ( bucket, hash) . await ,
132
142
}
133
143
}
134
144
135
145
pub async fn get_modified ( & mut self , bucket : & str , path : & str ) -> Result < i64 , Box < dyn Error > > {
146
+ debug ! ( "Getting modified time for bucket: {}, path: {}" , bucket, path) ;
136
147
match self {
137
148
KVStorage :: Postgres ( storage) => storage. get_modified ( bucket, path) . await ,
138
149
KVStorage :: SQLite ( storage) => storage. get_modified ( bucket, path) . await ,
@@ -145,6 +156,10 @@ impl KVStorage {
145
156
path : & str ,
146
157
modified : i64 ,
147
158
) -> Result < ( ) , Box < dyn Error > > {
159
+ debug ! (
160
+ "Setting modified time for bucket: {}, path: {} to {}" ,
161
+ bucket, path, modified
162
+ ) ;
148
163
match self {
149
164
KVStorage :: Postgres ( storage) => storage. set_modified ( bucket, path, modified) . await ,
150
165
KVStorage :: SQLite ( storage) => storage. set_modified ( bucket, path, modified) . await ,
@@ -156,6 +171,7 @@ impl KVStorage {
156
171
bucket : & str ,
157
172
path : & str ,
158
173
) -> Result < ( ) , Box < dyn Error > > {
174
+ debug ! ( "Deleting modified time for bucket: {}, path: {}" , bucket, path) ;
159
175
match self {
160
176
KVStorage :: Postgres ( storage) => storage. delete_modified ( bucket, path) . await ,
161
177
KVStorage :: SQLite ( storage) => storage. delete_modified ( bucket, path) . await ,
@@ -167,6 +183,7 @@ impl KVStorage {
167
183
bucket : & str ,
168
184
path : & str ,
169
185
) -> Result < String , Box < dyn Error > > {
186
+ debug ! ( "Getting ref file for bucket: {}, path: {}" , bucket, path) ;
170
187
match self {
171
188
KVStorage :: Postgres ( storage) => storage. get_ref_file ( bucket, path) . await ,
172
189
KVStorage :: SQLite ( storage) => storage. get_ref_file ( bucket, path) . await ,
@@ -179,6 +196,10 @@ impl KVStorage {
179
196
path : & str ,
180
197
hash : & str ,
181
198
) -> Result < ( ) , Box < dyn Error > > {
199
+ debug ! (
200
+ "Setting ref file for bucket: {}, path: {} to {}" ,
201
+ bucket, path, hash
202
+ ) ;
182
203
match self {
183
204
KVStorage :: Postgres ( storage) => storage. set_ref_file ( bucket, path, hash) . await ,
184
205
KVStorage :: SQLite ( storage) => storage. set_ref_file ( bucket, path, hash) . await ,
@@ -190,6 +211,7 @@ impl KVStorage {
190
211
bucket : & str ,
191
212
path : & str ,
192
213
) -> Result < ( ) , Box < dyn Error > > {
214
+ debug ! ( "Deleting ref file for bucket: {}, path: {}" , bucket, path) ;
193
215
match self {
194
216
KVStorage :: Postgres ( storage) => storage. delete_ref_file ( bucket, path) . await ,
195
217
KVStorage :: SQLite ( storage) => storage. delete_ref_file ( bucket, path) . await ,
0 commit comments