Skip to content

Commit

Permalink
actually handle oversized chunks
Browse files Browse the repository at this point in the history
  • Loading branch information
duplexsystem committed Apr 8, 2023
1 parent 2f05b48 commit b0a4662
Show file tree
Hide file tree
Showing 6 changed files with 38 additions and 14 deletions.
8 changes: 7 additions & 1 deletion .cargo/cargo.toml → .cargo/config.toml
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
[unstable]
build-std = ["core", "compiler_builtins", "alloc", "std", "panic_abort", "panic_unwind", "proc_macro", "unwind"]
build-std = ["core", "compiler_builtins", "alloc", "std", "panic_abort", "proc_macro"]
build-std-features = ["panic_immediate_abort"]

[build]
target = "x86_64-unknown-linux-gnu"
Expand All @@ -9,3 +10,8 @@ rustflags = [
"-C", "link-arg=-fuse-ld=mold",
"-C", "link-arg=-flto",
]

[env]
CC = "clang"
AR = "llvm-ar"
CFLAGS = "-O3 -fuse-ld=mold -flto"
9 changes: 6 additions & 3 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,9 @@ edition = "2021"
# Utilites
once_cell = { version = "1.17.1", features = ["parking_lot"] } # For dynamic dyspatch tables
parking_lot = { version = "0.12.1", features = ["hardware-lock-elision"] } # Enable faster backed for oncecell
hashbrown = { version = "0.*", features = ["inline-more"] }
hashbrown = { version = "0.12.3", features = ["inline-more"] }
dashmap = "5.4.0"
ahash = "0.8.3"
ahash = "0.7.6"
libc = "0.2.140" # for low level utils
smallvec = { version = "1.10.0", features = ["write", "union", "const_generics", "const_new"] }
glidesort = "0.1.2"
Expand All @@ -34,7 +34,10 @@ positioned-io = "0.3.1"
io-uring = { version = "0.5.13", features = ["unstable"] }

[lib]
#crate_type = ["cdylib"]
#crate_type = ["dylib"]

[profile.release]
lto = true
strip = true
panic = "abort"
codegen-units = 1
7 changes: 7 additions & 0 deletions rust-toolchain.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
[toolchain]
channel = "nightly-2023-03-04"
components = ["rust-src", "rustc-dev", "llvm-tools-preview"]
# commit_hash = 44cfafe2fafe816395d3acc434663a45d5178c41

# Whenever changing the nightly channel, update the commit hash above, and make
# sure to change REQUIRED_TOOLCHAIN in crates/rustc_codegen_spirv/src/build.rs also.
18 changes: 12 additions & 6 deletions src/chunk.rs
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@ impl Chunk {

let compression_type = CompressionType::from_u8(data[location + 4]).unwrap();

let oversized = compression_type_byte == 82;
let oversized = compression_type_byte & 128 != 0;

let data_start = location + 5;
let data_end = location + 4 + length as usize;
Expand Down Expand Up @@ -147,11 +147,17 @@ impl Chunk {
));
}

let compressed_data = static_region_metadata
.file
.as_ref()
.unwrap()
.read_file(self.chunk_header_data.data_range.clone())?;
let compressed_data = match self.chunk_header_data.oversized {
true => {
let file = self.data.oversized_data.as_ref().unwrap();
file.read_file(0..file.file_size)?
}
false => static_region_metadata
.file
.as_ref()
.unwrap()
.read_file(self.chunk_header_data.data_range.clone())?,
};

let data = self
.chunk_header_data
Expand Down
8 changes: 5 additions & 3 deletions src/memory_mapped_file.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,8 @@ use crate::{random_file, sequential_file};
pub(crate) struct MemoryMappedFile {
file: Box<dyn SpecializedFile + Send + Sync>,
data: MmapMut,
pub(crate) memory_size: usize,
memory_size: usize,
pub(crate) file_size: usize,
}

impl MemoryMappedFile {
Expand Down Expand Up @@ -42,11 +43,12 @@ impl MemoryMappedFile {
}
};

Ok((MemoryMappedFile {
Ok(MemoryMappedFile {
file,
data,
memory_size,
}))
file_size: memory_size,
})
}

pub(crate) fn close_file(self) -> Result<(), Error> {
Expand Down
2 changes: 1 addition & 1 deletion src/region.rs
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ impl Region {
Path::new(&format!("{0}/r.{1}.{2}.mca", key.directory, key.x, key.z)),
true,
)?;
let end = ((file.memory_size as u32 / 4096) - 2).max(1);
let end = ((file.file_size as u32 / 4096) - 2).max(1);

let static_region_metadata = StaticRegionMetadata {
directory: key.directory,
Expand Down

0 comments on commit b0a4662

Please sign in to comment.