Skip to content

Commit

Permalink
Merge branch 'main' into dependabot/npm_and_yarn/archived/ui/multi-ce…
Browse files Browse the repository at this point in the history
…ff1a497b
  • Loading branch information
genedna committed Sep 10, 2024
2 parents fd7fe68 + 9bc5a05 commit 9807964
Show file tree
Hide file tree
Showing 22 changed files with 167 additions and 125 deletions.
1 change: 1 addition & 0 deletions atlas/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
## Atlas Module
1 change: 1 addition & 0 deletions jupiter/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ path = "src/lib.rs"
callisto = { workspace = true }
common = { workspace = true }
mercury = { workspace = true }

sea-orm = { workspace = true, features = [
"sqlx-postgres",
"sqlx-mysql",
Expand Down
2 changes: 1 addition & 1 deletion jupiter/README.md
Original file line number Diff line number Diff line change
@@ -1 +1 @@
## Jupiter Module
## Jupiter Module - Monorepo and Mega Database Storage Engine
2 changes: 0 additions & 2 deletions jupiter/callisto/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,6 @@ name = "callisto"
path = "src/lib.rs"

[dependencies]
common = { workspace = true }

serde = { workspace = true, features = ["derive"] }
serde_json = { workspace = true }
chrono = { workspace = true }
Expand Down
1 change: 1 addition & 0 deletions jupiter/callisto/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
### Callisto - ORM Model for Mega
64 changes: 3 additions & 61 deletions jupiter/src/lfs_storage/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,15 +22,9 @@ pub struct BlobLink {

#[async_trait]
pub trait LfsStorage: Sync + Send {

async fn get_ref(&self, repo_id: i64, ref_name: &str) -> Result<String, MegaError>;

async fn put_ref(
&self,
repo_id: i64,
ref_name: &str,
ref_hash: &str,
) -> Result<(), MegaError>;
async fn put_ref(&self, repo_id: i64, ref_name: &str, ref_hash: &str) -> Result<(), MegaError>;

async fn delete_ref(&self, repo_id: i64, ref_name: &str) -> Result<(), MegaError>;

Expand All @@ -43,57 +37,7 @@ pub trait LfsStorage: Sync + Send {

async fn get_object(&self, object_id: &str) -> Result<Bytes, MegaError>;

async fn put_object(
&self,
object_id: &str,
body_content: &[u8],
) -> Result<String, MegaError>;

// async fn parse_blob_link(&self, data: Vec<u8>) -> Result<BlobLink, MegaError> {
// let mut reader = BufReader::new(data.as_slice());
// let mut blink = BlobLink::default();
// // for line in reader.lines() {
// // let str = line.unwrap();
// // }
// let mut buf = String::new();
// reader.read_line(&mut buf).unwrap();
// blink.version = buf.split_whitespace().next();
// let result = self.get_by_path(&blink.storge_location).await.unwrap();
// Ok(blink)
// }

// save a entry and return the b_link file
// async fn convert_blink(&self, entry: &Entry) -> Result<Vec<u8>, MegaError> {
// let location = self
// .put_object( &entry.hash.to_plain_str(), &entry.data)
// .await
// .unwrap();
// let handlebars = Handlebars::new();

// let path = env::current_dir().unwrap().join("b_link.txt");
// let mut file = File::open(path).unwrap();
// let mut template = String::new();
// file.read_to_string(&mut template).unwrap();

// let mut context = serde_json::Map::new();
// context.insert(
// "objectType".to_string(),
// serde_json::json!(entry.obj_type.to_string()),
// );
// context.insert(
// "sha1".to_string(),
// serde_json::json!(entry.hash.to_plain_str()),
// );
// context.insert(
// "type".to_string(),
// serde_json::json!(self.get_storage_type().to_string()),
// );
// context.insert("location".to_string(), serde_json::json!(location));

// let rendered = handlebars.render_template(&template, &context).unwrap();

// Ok(rendered.into_bytes())
// }
async fn put_object(&self, object_id: &str, body_content: &[u8]) -> Result<String, MegaError>;

fn exist_object(&self, object_id: &str) -> bool;

Expand All @@ -113,9 +57,7 @@ pub trait LfsStorage: Sync + Send {

pub async fn init(storage_type: String, base_path: PathBuf) -> Arc<dyn LfsStorage> {
match storage_type.as_str() {
"LOCAL" => {
Arc::new(LocalStorage::init(base_path))
}
"LOCAL" => Arc::new(LocalStorage::init(base_path)),
// "REMOTE" => Arc::new(RemoteStorage::init(path).await),
_ => unreachable!(
"Not supported config, MEGA_OBJ_STORAGE_TYPE should be 'LOCAL' or 'REMOTE'"
Expand Down
1 change: 1 addition & 0 deletions mega/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ gateway = { workspace = true }
common = { workspace = true }
ceres = { workspace = true }
taurus = { workspace = true }

serde = { workspace = true, features = ["derive"] }
tokio = { workspace = true, features = ["macros"] }
clap = { workspace = true, features = ["derive"] }
Expand Down
1 change: 1 addition & 0 deletions mercury/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ edition = "2021"
delta = { path = "delta" }
common = { workspace = true }
callisto = { workspace = true }

flate2 = { workspace = true, features = [
"zlib",
] } # enable linking against the libz(C lib); better performance
Expand Down
2 changes: 1 addition & 1 deletion mercury/README.md
Original file line number Diff line number Diff line change
@@ -1 +1 @@
## Mercury Module
## Mercury Module - Git Internal Module
11 changes: 9 additions & 2 deletions mercury/src/internal/object/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,12 @@ use std::{
str::FromStr,
};

use callisto::{git_blob, git_commit, git_tag, git_tree, mega_blob, mega_commit, mega_tag, mega_tree, raw_blob};
use sha1::Digest;

use callisto::{
git_blob, git_commit, git_tag, git_tree, mega_blob, mega_commit, mega_tag, mega_tree, raw_blob,
};

use crate::internal::object::types::ObjectType;
use crate::internal::object::{blob::Blob, commit::Commit, tag::Tag, tree::Tree};
use crate::internal::zlib::stream::inflate::ReadBoxed;
Expand All @@ -37,7 +40,11 @@ pub trait ObjectTrait: Send + Sync + Display {
read.read_to_end(&mut content).unwrap();
let h = read.hash.clone();
let hash_str = h.finalize();
Self::from_bytes(&content, SHA1::from_str(&format!("{:x}", hash_str)).unwrap()).unwrap()
Self::from_bytes(
&content,
SHA1::from_str(&format!("{:x}", hash_str)).unwrap(),
)
.unwrap()
}

/// Returns the type of the object.
Expand Down
9 changes: 3 additions & 6 deletions mercury/src/internal/pack/cache.rs
Original file line number Diff line number Diff line change
@@ -1,20 +1,17 @@

use std::path::Path;
use std::path::PathBuf;
use std::sync::atomic::{AtomicBool, Ordering};
use std::sync::{Arc, Mutex};
use std::thread::sleep;
use std::{fs, io};

use crate::internal::pack::cache_object::{ArcWrapper, CacheObject, MemSizeRecorder};
use crate::time_it;
use dashmap::{DashMap, DashSet};
use lru_mem::LruCache;
use threadpool::ThreadPool;
use crate::hash::SHA1;

use super::cache_object::FileLoadStore;

use crate::time_it;
use crate::hash::SHA1;
use crate::internal::pack::cache_object::{ArcWrapper, CacheObject, MemSizeRecorder, FileLoadStore};

pub trait _Cache {
fn new(mem_size: Option<usize>, tmp_path: PathBuf, thread_num: usize) -> Self
Expand Down
3 changes: 2 additions & 1 deletion mercury/src/internal/pack/cache_object.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,11 @@ use std::sync::atomic::{AtomicBool, AtomicUsize, Ordering};
use std::{fs, io};
use std::{ops::Deref, sync::Arc};

use crate::internal::pack::utils;
use lru_mem::{HeapSize, MemSize};
use serde::{Deserialize, Serialize};
use threadpool::ThreadPool;

use crate::internal::pack::utils;
use crate::{hash::SHA1, internal::object::types::ObjectType};
use crate::internal::pack::entry::Entry;

Expand Down
8 changes: 4 additions & 4 deletions mercury/src/internal/pack/decode.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,24 +5,24 @@ use std::sync::{Arc, mpsc};
use std::sync::mpsc::{Receiver, Sender};
use std::thread::{self, JoinHandle};
use std::time::Instant;

use axum::Error;
use bytes::Bytes;

use flate2::bufread::ZlibDecoder;
use futures_util::{Stream, StreamExt};
use threadpool::ThreadPool;
use uuid::Uuid;

use crate::errors::GitError;
use crate::hash::SHA1;
use crate::internal::object::types::ObjectType;

use super::cache::_Cache;
use crate::internal::pack::cache::Caches;
use crate::internal::pack::cache::_Cache;
use crate::internal::pack::cache_object::{CacheObject, MemSizeRecorder};
use crate::internal::pack::waitlist::Waitlist;
use crate::internal::pack::wrapper::Wrapper;
use crate::internal::pack::{utils, Pack, DEFAULT_TMP_DIR};
use uuid::Uuid;
use crate::internal::pack::channel_reader::ChannelReader;
use crate::internal::pack::entry::Entry;

Expand Down Expand Up @@ -458,7 +458,7 @@ impl Pack {
// if self.clean_tmp {
// self.caches.remove_tmp_dir();
// }

Ok(())
}

Expand Down
1 change: 1 addition & 0 deletions mercury/src/internal/pack/entry.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
use std::hash::{Hash, Hasher};

use serde::{Deserialize, Serialize};

use crate::hash::SHA1;
Expand Down
10 changes: 5 additions & 5 deletions mercury/src/internal/pack/mod.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
//!
//!
//! ## Reference
//! 1. Git Pack-Format [Introduce](https://git-scm.com/docs/pack-format)
//!
Expand All @@ -12,14 +12,14 @@ pub mod cache_object;
pub mod entry;
pub mod channel_reader;

use crate::hash::SHA1;
use threadpool::ThreadPool;
use std::sync::Arc;
use std::sync::atomic::AtomicUsize;

use crate::hash::SHA1;
use crate::internal::object::ObjectTrait;
use crate::internal::pack::waitlist::Waitlist;

use self::cache::Caches;
use crate::internal::pack::cache::Caches;

const DEFAULT_TMP_DIR: &str = "./.cache_temp";
pub struct Pack {
Expand All @@ -36,4 +36,4 @@ pub struct Pack {

#[cfg(test)]
mod tests {
}
}
41 changes: 21 additions & 20 deletions mercury/src/internal/pack/utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,26 +2,27 @@ use std::fs;
use std::io::{self, Read};
use std::path::Path;
use sha1::{Digest, Sha1};

use crate::hash::SHA1;
use crate::internal::object::types::ObjectType;

/// Checks if the reader has reached EOF (end of file).
///
///
/// It attempts to read a single byte from the reader into a buffer.
/// If `Ok(0)` is returned, it means no byte was read, indicating
/// If `Ok(0)` is returned, it means no byte was read, indicating
/// that the end of the stream has been reached and there is no more
/// data left to read.
///
/// Any other return value means that data was successfully read, so
/// the reader has not reached the end yet.
/// the reader has not reached the end yet.
///
/// # Arguments
///
/// * `reader` - The reader to check for EOF state
///
/// * `reader` - The reader to check for EOF state
/// It must implement the `std::io::Read` trait
///
/// # Returns
///
/// # Returns
///
/// true if the reader reached EOF, false otherwise
#[allow(unused)]
pub fn is_eof(reader: &mut dyn Read) -> bool {
Expand Down Expand Up @@ -102,7 +103,7 @@ pub fn read_type_and_varint_size<R: Read>(stream: &mut R, offset: &mut usize) ->
}

/// Reads a variable-length integer (VarInt) encoded in little-endian format from a source implementing the Read trait.
///
///
/// The VarInt encoding uses the most significant bit (MSB) of each byte as a continuation bit.
/// The continuation bit being 1 indicates that there are following bytes.
/// The actual integer value is encoded in the remaining 7 bits of each byte.
Expand All @@ -122,7 +123,7 @@ pub fn read_varint_le<R: Read>(reader: &mut R) -> io::Result<(u64, usize)> {
// Bit shift for the next byte
let mut shift = 0;
// Number of bytes read
let mut offset = 0;
let mut offset = 0;

loop {
// A buffer to read a single byte
Expand All @@ -131,19 +132,19 @@ pub fn read_varint_le<R: Read>(reader: &mut R) -> io::Result<(u64, usize)> {
reader.read_exact(&mut buf)?;

// The byte just read
let byte = buf[0];
if shift > 63 {
let byte = buf[0];
if shift > 63 {
// VarInt too long for u64
return Err(io::Error::new(io::ErrorKind::InvalidData, "VarInt too long"));
}

// Take the lower 7 bits of the byte
let byte_value = (byte & 0x7F) as u64;
let byte_value = (byte & 0x7F) as u64;
// Add the byte value to the result, considering the shift
value |= byte_value << shift;
value |= byte_value << shift;

// Increment the byte count
offset += 1;
offset += 1;
// Check if the MSB is 0 (last byte)
if byte & 0x80 == 0 {
break;
Expand Down Expand Up @@ -315,7 +316,7 @@ mod tests {
assert!(is_eof(&mut reader));
}

#[test]
#[test]
fn not_eof() {
let mut reader = Cursor::new(&b"abc"[..]);
assert!(!is_eof(&mut reader));
Expand All @@ -336,9 +337,9 @@ mod tests {
Err(io::Error::new(io::ErrorKind::Other, "error"))
}
}

let mut reader = BrokenReader;
assert!(!is_eof(&mut reader));
assert!(!is_eof(&mut reader));
}

// Test case for a byte without a continuation bit (most significant bit is 0)
Expand Down Expand Up @@ -423,7 +424,7 @@ mod tests {

assert_eq!(offset, 1); // Offset is 1
assert_eq!(type_bits, 1); // Expected type is 1
// Expected size is 15
// Expected size is 15
assert_eq!(size, 15);
}

Expand Down Expand Up @@ -483,7 +484,7 @@ mod tests {

assert!(result.is_err());
}

#[test]
fn test_read_offset_encoding(){
let data:Vec<u8> = vec![0b_1101_0101,0b_0000_0101];
Expand All @@ -492,4 +493,4 @@ mod tests {
assert!(result.is_ok());
assert_eq!(result.unwrap(), (11013, 2));
}
}
}
Loading

0 comments on commit 9807964

Please sign in to comment.