Skip to content

Commit 79e741e

Browse files
committed
fmt
1 parent abf08d7 commit 79e741e

File tree

4 files changed

+43
-20
lines changed

4 files changed

+43
-20
lines changed

src/lib/storage/src/lmdb.rs

+2-3
Original file line numberDiff line numberDiff line change
@@ -194,11 +194,10 @@ impl LmdbBackend {
194194
rw_txn.commit()?;
195195
Ok(())
196196
})
197-
.await
198-
.expect("Failed to run tokio task")
197+
.await
198+
.expect("Failed to run tokio task")
199199
}
200200

201-
202201
pub async fn exists(&self, table: String, key: u128) -> Result<bool, StorageError> {
203202
let env = self.env.clone();
204203
tokio::task::spawn_blocking(move || {

src/lib/world/src/db_functions.rs

+8-3
Original file line numberDiff line numberDiff line change
@@ -130,7 +130,10 @@ pub(crate) async fn save_chunk_internal(world: &World, chunk: Chunk) -> Result<(
130130
Ok(())
131131
}
132132

133-
pub(crate) async fn save_chunk_internal_batch(world: &World, chunks: Vec<Chunk>) -> Result<(), WorldError> {
133+
pub(crate) async fn save_chunk_internal_batch(
134+
world: &World,
135+
chunks: Vec<Chunk>,
136+
) -> Result<(), WorldError> {
134137
// Prepare the batch data for the upsert
135138
let mut batch_data = Vec::new();
136139

@@ -144,12 +147,14 @@ pub(crate) async fn save_chunk_internal_batch(world: &World, chunks: Vec<Chunk>)
144147
}
145148

146149
// Perform the batch upsert
147-
world.storage_backend.batch_upsert("chunks".to_string(), batch_data).await?;
150+
world
151+
.storage_backend
152+
.batch_upsert("chunks".to_string(), batch_data)
153+
.await?;
148154

149155
Ok(())
150156
}
151157

152-
153158
pub(crate) async fn load_chunk_internal(
154159
world: &World,
155160
compressor: &Compressor,

src/lib/world/src/errors.rs

-1
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,6 @@ impl From<AcquireError> for WorldError {
5050
}
5151
}
5252

53-
5453
impl From<std::io::Error> for WorldError {
5554
fn from(err: std::io::Error) -> Self {
5655
match err.kind() {

src/lib/world/src/importing.rs

+33-13
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
1-
use crate::Chunk;
21
use crate::db_functions::save_chunk_internal_batch; // Ensure this is the batch save function
32
use crate::errors::WorldError;
43
use crate::vanilla_chunk_format::VanillaChunk;
4+
use crate::Chunk;
55
use crate::World;
66
use ferrumc_anvil::load_anvil_file;
77
use ferrumc_general_purpose::paths::BetterPathExt;
@@ -28,17 +28,23 @@ impl World {
2828
progress: Arc<ProgressBar>,
2929
processed_since_flush: Arc<AtomicU64>,
3030
) -> Result<(), WorldError> {
31-
let chunk_objects: Vec<Chunk> = chunks.into_iter().filter_map(|chunk| chunk.to_custom_format().ok()).collect();
31+
let chunk_objects: Vec<Chunk> = chunks
32+
.into_iter()
33+
.filter_map(|chunk| chunk.to_custom_format().ok())
34+
.collect();
3235

3336
let mut success_count = 0;
34-
if let Ok(()) = save_chunk_internal_batch(self, chunk_objects.clone()/*temp clone*/).await {
37+
if let Ok(()) = save_chunk_internal_batch(self, chunk_objects.clone() /*temp clone*/).await
38+
{
3539
success_count = chunk_objects.len(); // Increment by the number of chunks successfully saved
3640
}
3741

3842
progress.inc(success_count.try_into().unwrap()); // Convert success_count to u64
3943

4044
// Flush logic remains the same
41-
let total_processed = processed_since_flush.fetch_add(success_count as u64, Ordering::Relaxed) + success_count as u64;
45+
let total_processed = processed_since_flush
46+
.fetch_add(success_count as u64, Ordering::Relaxed)
47+
+ success_count as u64;
4248
if total_processed >= FLUSH_INTERVAL {
4349
self.storage_backend.flush().await?;
4450
processed_since_flush.store(0, Ordering::Relaxed);
@@ -48,7 +54,6 @@ impl World {
4854
Ok(())
4955
}
5056

51-
5257
fn get_chunk_count(&self, import_dir: &PathBuf) -> Result<u64, WorldError> {
5358
info!("Counting chunks in import directory...");
5459
let regions_dir = import_dir.join("region").read_dir()?;
@@ -63,10 +68,8 @@ impl World {
6368
}
6469

6570
if let Ok(anvil_file) = load_anvil_file(entry.path()) {
66-
chunk_count.fetch_add(
67-
anvil_file.get_locations().len() as u64,
68-
Ordering::Relaxed,
69-
);
71+
chunk_count
72+
.fetch_add(anvil_file.get_locations().len() as u64, Ordering::Relaxed);
7073
}
7174
Ok(())
7275
})?;
@@ -114,7 +117,11 @@ impl World {
114117
let anvil_file = match load_anvil_file(region_entry.path()) {
115118
Ok(file) => file,
116119
Err(e) => {
117-
error!("Failed to load region file {}: {}", region_entry.path().display(), e);
120+
error!(
121+
"Failed to load region file {}: {}",
122+
region_entry.path().display(),
123+
e
124+
);
118125
continue;
119126
}
120127
};
@@ -125,15 +132,25 @@ impl World {
125132
current_batch.push(vanilla_chunk);
126133

127134
if current_batch.len() >= BATCH_SIZE {
128-
let batch = std::mem::replace(&mut current_batch, Vec::with_capacity(BATCH_SIZE));
135+
let batch = std::mem::replace(
136+
&mut current_batch,
137+
Vec::with_capacity(BATCH_SIZE),
138+
);
129139
let progress_clone = Arc::clone(&progress);
130140
let self_clone = self.clone();
131141
let permit = Arc::clone(&semaphore).acquire_owned().await?;
132142
let processed_since_flush_clone = Arc::clone(&processed_since_flush);
133143

134144
task_set.spawn(async move {
135145
let _permit = permit; // Keep permit alive for the duration of the task
136-
if let Err(e) = self_clone.process_chunk_batch(batch, progress_clone, processed_since_flush_clone).await {
146+
if let Err(e) = self_clone
147+
.process_chunk_batch(
148+
batch,
149+
progress_clone,
150+
processed_since_flush_clone,
151+
)
152+
.await
153+
{
137154
error!("Batch processing error: {}", e);
138155
}
139156
});
@@ -152,7 +169,10 @@ impl World {
152169

153170
task_set.spawn(async move {
154171
let _permit = permit;
155-
if let Err(e) = self_clone.process_chunk_batch(current_batch, progress_clone, processed_since_flush_clone).await {
172+
if let Err(e) = self_clone
173+
.process_chunk_batch(current_batch, progress_clone, processed_since_flush_clone)
174+
.await
175+
{
156176
error!("Final batch processing error: {}", e);
157177
}
158178
});

0 commit comments

Comments
 (0)