Upgrade to Pro
— share decks privately, control downloads, hide ads and more …
Speaker Deck
Sign up for free
Menu
Search
Features
All features
Private URLs
Password Protection
Custom URLS
Scheduled publishing
Remove Branding
Restrict embedding
Deck Collections
Notes
Features
All features
Private URLs
Password Protection
Custom URLS
Scheduled publishing
Remove Branding
Restrict embedding
Deck Collections
Notes
Explore
Featured decks
Featured speakers
Programming
Technology
Storyboards
Explore
Featured decks
Featured speakers
Programming
Technology
Storyboards
Pricing
Search
Sign in
Sign up for free
自作オブジェクトストレージをRustで
Search
Sponsored
·
Your Podcast. Everywhere. Effortlessly.
Share. Educate. Inspire. Entertain. You do you. We'll handle the rest.
→
noharu36
December 01, 2025
Programming
89
0
Share
Embed
Copy iframe code
Copy JS code
Copy link
Start on current slide
自作オブジェクトストレージをRustで
noharu36
December 01, 2025
More Decks by noharu36
See All by noharu36
皆さんはHaskellをご存知です_しかし皆さんはHaskellが読めません_.pdf
noharu36
0
54
検証!会津は本当に地盤が硬いのか?
noharu36
0
42
ファミコンに思いを馳せる〜エミュレータ自作を添えて〜
noharu36
0
46
shell自作した話
noharu36
0
41
Rustを布教したい
noharu36
0
58
neofetchよ、永遠に
noharu36
0
43
ISSの軌道計算をRustで
noharu36
0
44
Other Decks in Programming
See All in Programming
[JA] Domain Modeling with Vanilla Rails: 「操作」から再考するRailsの設計論
yasaichi
3
440
Unity6 URPによる海底をテーマにしたVJシステムの解説 | Unity Shader 完全に理解した 勉強会
gam0022
0
370
設計次第でAIコードの読む量は減らせる / designing-for-code-reading
minodriven
35
17k
iOS 27でニュースアプリはどう変わる!? 〜日経電子版の新機能対応と、開発事例から〜
lynnswap
7
13k
AWS CDKのカスタムリソースでContinuum(旧Security Agent)を実装した話 | Implementing Continuum (formerly Security Agent) via AWS CDK Custom Resource
akihisaikeda
2
150
When benchmarks go bad - what I learned from measuring performance wrong
hollycummins
0
220
sbt 2.0: takeoff
eed3si9n
0
160
AI主導のプログラミング学習アプリを作ってみた
econanringo
0
180
Augmenting AI with the Power of Jakarta EE
ivargrimstad
0
220
月間100万人のサービス刷新で、 技術選定をHonoに振り切った話
yutobara
8
6.7k
作れる、でも消せるか?──安全に「枯らして消す」機能削除術 / Drain, Then Delete
chobishiba
2
800
npm との違いを手がかりにGo の依存管理を理解したい
optim
0
780
Featured
See All Featured
Amusing Abliteration
ianozsvald
1
350
Why Mistakes Are the Best Teachers: Turning Failure into a Pathway for Growth
auna
0
330
The Pragmatic Product Professional
lauravandoore
37
7.5k
Faster Mobile Websites
deanohume
310
32k
Mobile First: as difficult as doing things right
swwweet
225
10k
Self-Hosted WebAssembly Runtime for Runtime-Neutral Checkpoint/Restore in Edge–Cloud Continuum
chikuwait
0
890
Primal Persuasion: How to Engage the Brain for Learning That Lasts
tmiket
0
500
AI Search: Implications for SEO and How to Move Forward - #ShenzhenSEOConference
aleyda
1
1.4k
4 Signs Your Business is Dying
shpigford
187
23k
Evolving SEO for Evolving Search Engines
ryanjones
0
330
Noah Learner - AI + Me: how we built a GSC Bulk Export data pipeline
techseoconnect
PRO
0
460
Exploring the relationship between traditional SERPs and Gen AI search
raygrieselhuber
PRO
4
4.4k
Transcript
自作オブジェクトストレージを Rustで 休学中 harukun
自己紹介 { name: 能島明希 handle: harukun origin: 広島->岡山->大阪->東京->会津 tech: {
front-end: React+TS backend: Rust, Go etc: Rust, Haskell Rust: Rust } favorites: Tobacco, BoyScout, Rust, Neovim, NixOS Twitter(x): https://twitter.com/pieceofharuki Blog: https://zenn.dev/haru_blog }
オブジェクトストレージとは • データをオブジェクト単位で扱う • ディレクトリのような階層構造は持たず、データは巨大な記憶領域の中にフラットに格納される • 保存できるオブジェクト数に(理論上)制限がない • 一般的に分散ストレージで構成されており、スケールアウトしやすい •
他のストレージシステムと比べて低速であり、更新頻度が高く高速な読み書きを要求するデータの管理に は向いてない
オブジェクトストレージ自作してみた
注意 このLTは、オブジェクトストレージを使ったことがない人間が、オブジェクトストレージって多分こんなもんじゃね?(鼻ホ ジ)と言いながら作った制作物を発表するLTです。 開発にあたって、dwango様とmirrativ様の技術ブログを参考にしました https://dwango.github.io/articles/frugalos/ https://tech.mirrativ.stream/entry/2023/10/20/115202
Why Rustでものづくりしたかった(いつも通り) ↓ DBよくわかんない、理解するために自作するか、 NoSQLならSQLパーサーなくて楽そうやな ... ↓ さくしょーがオブジェクトストレージ作れって言った ↓ まあオブジェクトストレージも全くわかんないからちょうどいいし作るか
...
技術スタック
外部クレート [dependencies] reed-solomon-erasure = "6.0.0" bytes = "1.10.1" tokio =
{ version = "1.44.2", features = ["full"] } anyhow = "1.0.98" axum={ version = "0.8.3", features = ["multipart"] } serde = { version = "1.0.219", features = ["derive"] } serde_json = "1.0.140" futures = "0.3.31" tokio-util = { version = "0.7.14", features = ["io"] } mime_guess = "2.0.5" tower-http = { version = "0.6.2", features = ["limit"] } rayon = "1.10.0" tracing = "0.1.41" tracing-subscriber = { version = "0.3.19", features = ["env-filter", "json"] } sqlx = { version = "0.8", features = [ "runtime-tokio", "sqlite" ] } chrono = "0.4.41" dotenvy = "0.15.7" [dependencies.uuid] version = "1.16.0" features = ["v4"]
軽く説明 • reed_solomon_erasure: イレイジャーコーディングの部分をよしなにやってくれる • tokio, tower_http, axum: Rustの非同期ランタイムとかWebフレームワークとか。
サーバーをたてる上で使う部分 • tracing: ログをいい感じに出してくれるやつ • sqlx: DB接続ライブラリ。ORMではない。マクロを使うとコンパイル時チェックが優秀 • anyhow: エラー管理ライブラリ。エラーの型を脳死で統合できるので良くも悪くも楽できる
構成 • benches/ : ベンチマークを計測するためのコードを置く • migrations/ : マイグレーションファイル •
src/handler/ : REST APIに対応する関数とか • src/db.rs : DBにアクセスするやつ • src/encode.rs , src/decode.rs : データのエンコード・デコー ド、ストレージへの格納・ロードの処理 • src/server.rs : サーバーの設定とか
ルーティングの例 #[instrument] fn object_routes() -> Router<MetadataStore> { Router::new() .route( "/bucket/{:bucket_name}/{:object_id}",
post(post_object).get(get_object).delete(delete_object), ) .layer(DefaultBodyLimit::disable()) .layer(RequestBodyLimitLayer::new(3 * 1024 * 1024 * 1024)) } /bucket/{bucket_name}/{object_id}に POST、GET、DELETEのメソッドをはやしている Bodyのサイズを3GBまでに制限している
POSTの処理 sample.mp4 (100mb) post_object( Path((bucket_name, object_id)), State(store), mut multipart )
save_shards(shards,object_id) store_data(bytes, id) encode_file(content) /bucket/{bucket_name}/{object_id}に POSTリクエストを送る multipart形式でデータを受け取る。 bucketが存在しているかをチェックし、メタデータを作成 してDBに登録する。 データをBytesに変換してメモリに読み込み、 store_data 関数の引数にする bytesをbytesmutに変換し、 encode_file関数の引数にする reed-solomon符号を用いてデータを分割し、 Result<Vec<BytesMut>を返す ベクタのインデックスと object_idを組み合わせてハッシュ化し、 その値を用いて(おそらくなるべくなんとなく)データが均一に分 散されるようストレージに保存する
IntoResponse post, deleteの関数の返り値は特定の型ではなく Impl IntoResponseとしている src/handler/api.rsで共通のレスポンスの型を定義し ている #[derive(Debug, Serialize)] struct
ApiResponse<T> { status: String, data: T, } #[derive(Debug, Serialize)] struct ApiError { status: String, message: String, } pub enum ApiResult<T> { Success(StatusCode, T), Error(StatusCode, String), } impl<T: Serialize> IntoResponse for ApiResult<T> { fn into_response(self) -> axum::response::Response { match self { ApiResult::Success(status, data) => ( status, Json(ApiResponse { status: "success".to_string(), data, }), ) .into_response(), ApiResult::Error(status, message) => ( status, Json(ApiError { status: "error".to_string(), message, }), ) .into_response(), } } }
できたもの https://github.com/noharu36/t3
今後 • メタデータをもっと豊富に(あと多分メタデータの管理方法間違ってる) • 認証・認可 • 格納先をちゃんとストレージにする(ロードバランサーとかも必要かも) • S3互換のAPIの実装
まとめ • 今までやってこなかったサーバー周りを Rustでかけてよかった • DB(SQL)、オブジェクトストレージへの理解度がほんの少し上がった • 次はNoSQL DB自作しようかな (俺が作ったのは本当にオブジェクトストレージなのか
...???)
THE YODAN 今年もセキュキャンに申し込みました。 年齢的に今回がラストチャンスなので死ぬ気で課題書きます ... 乞うご期待!