-
Notifications
You must be signed in to change notification settings - Fork 43
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #46 from bancek/feature-add-rados-striper
Add support for Rados striper
- Loading branch information
Showing
13 changed files
with
879 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
/target |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,3 +2,4 @@ target | |
**/*.rs.bk | ||
Cargo.lock | ||
vscode.code-workspace | ||
.build-docker |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
FROM buildpack-deps:xenial | ||
|
||
ENV RUSTUP_HOME=/usr/local/rustup \ | ||
CARGO_HOME=/usr/local/cargo \ | ||
PATH=/usr/local/cargo/bin:$PATH \ | ||
RUST_VERSION=1.38.0 | ||
|
||
RUN set -eux; \ | ||
dpkgArch="$(dpkg --print-architecture)"; \ | ||
case "${dpkgArch##*-}" in \ | ||
amd64) rustArch='x86_64-unknown-linux-gnu'; rustupSha256='36285482ae5c255f2decfab27d32ba19465804cb3ddf5a23e6ff2a7b0f6e0250' ;; \ | ||
armhf) rustArch='armv7-unknown-linux-gnueabihf'; rustupSha256='cb20e54566d4b13434dea1776a961cf7f97afcc292cb4b0fec533503dd2434d0' ;; \ | ||
arm64) rustArch='aarch64-unknown-linux-gnu'; rustupSha256='58e19ae12101103ccc50b04a2579b9238163f87a27da5078cefc900098f257ab' ;; \ | ||
i386) rustArch='i686-unknown-linux-gnu'; rustupSha256='d3c42fb8b25f87eb049b6177611eea7d4fd51273de4113706f43cccf5610cfc7' ;; \ | ||
*) echo >&2 "unsupported architecture: ${dpkgArch}"; exit 1 ;; \ | ||
esac; \ | ||
url="https://static.rust-lang.org/rustup/archive/1.19.0/${rustArch}/rustup-init"; \ | ||
wget "$url"; \ | ||
echo "${rustupSha256} *rustup-init" | sha256sum -c -; \ | ||
chmod +x rustup-init; \ | ||
./rustup-init -y --no-modify-path --default-toolchain $RUST_VERSION; \ | ||
rm rustup-init; \ | ||
chmod -R a+w $RUSTUP_HOME $CARGO_HOME; \ | ||
rustup --version; \ | ||
cargo --version; \ | ||
rustc --version; | ||
|
||
RUN apt-get update \ | ||
&& apt-get install apt-transport-https \ | ||
&& wget -q -O- 'https://download.ceph.com/keys/release.asc' | apt-key add - \ | ||
&& echo "deb https://download.ceph.com/debian-nautilus/ xenial main" > /etc/apt/sources.list.d/ceph.list \ | ||
&& apt-get update \ | ||
&& apt-get install -y --no-install-recommends \ | ||
uuid-runtime \ | ||
ceph-mgr ceph-mon ceph-osd ceph-mds \ | ||
librados-dev libradosstriper-dev | ||
|
||
# update crates.io index | ||
RUN cargo search --limit 0 | ||
|
||
WORKDIR /ceph-rust | ||
|
||
COPY micro-osd.sh / | ||
COPY setup-micro-osd.sh / | ||
COPY entrypoint.sh / | ||
|
||
CMD /entrypoint.sh |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
DOCKER_CI_IMAGE = ceph-rust-ci | ||
|
||
build: | ||
go build -v | ||
fmt: | ||
go fmt ./... | ||
test: | ||
go test -v ./... | ||
|
||
test-docker: .build-docker | ||
docker run --rm -it -v $(CURDIR):/ceph-rust $(DOCKER_CI_IMAGE) | ||
|
||
shell-docker: .build-docker | ||
docker run --rm -it -v $(CURDIR):/ceph-rust $(DOCKER_CI_IMAGE) bash | ||
# Now you can run | ||
# . /setup-micro-osd.sh | ||
# cargo build | ||
|
||
.build-docker: | ||
docker build -t $(DOCKER_CI_IMAGE) . | ||
@docker inspect -f '{{.Id}}' $(DOCKER_CI_IMAGE) > .build-docker |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
#!/bin/bash | ||
|
||
. /setup-micro-osd.sh | ||
|
||
set -e | ||
|
||
cargo test --features rados_striper | ||
|
||
cargo run --features rados_striper --example rados_striper |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,74 @@ | ||
extern crate ceph; | ||
extern crate nix; | ||
|
||
use std::env; | ||
use std::str; | ||
|
||
use nix::errno::Errno; | ||
|
||
use ceph::ceph as ceph_helpers; | ||
use ceph::error::RadosError; | ||
|
||
#[cfg(not(feature = "rados_striper"))] | ||
fn main() {} | ||
|
||
#[cfg(feature = "rados_striper")] | ||
fn main() { | ||
let user_id = "admin"; | ||
let config_file = env::var("CEPH_CONF").unwrap_or("/etc/ceph/ceph.conf".to_string()); | ||
let pool_name = "ceph-rust-test"; | ||
|
||
println!("Connecting to ceph"); | ||
let cluster = ceph_helpers::connect_to_ceph(user_id, &config_file).unwrap(); | ||
|
||
println!("Creating pool {}", pool_name); | ||
match cluster.rados_create_pool(pool_name) { | ||
Ok(_) => {} | ||
Err(RadosError::ApiError(Errno::EEXIST)) => { | ||
cluster.rados_delete_pool(pool_name).unwrap(); | ||
cluster.rados_create_pool(pool_name).unwrap(); | ||
} | ||
Err(err) => panic!("{:?}", err), | ||
} | ||
|
||
let object_name = "ceph-rust-test-object"; | ||
|
||
{ | ||
println!("Creating ioctx"); | ||
let ioctx = cluster.get_rados_ioctx(pool_name).unwrap(); | ||
|
||
println!("Creating rados striper"); | ||
let rados_striper = ioctx.get_rados_striper().unwrap(); | ||
|
||
println!("Writing test object"); | ||
rados_striper | ||
.rados_object_write(object_name, "lorem".as_bytes(), 0) | ||
.unwrap(); | ||
rados_striper | ||
.rados_object_write(object_name, " ipsum".as_bytes(), 5) | ||
.unwrap(); | ||
} | ||
|
||
{ | ||
println!("Creating ioctx"); | ||
let ioctx = cluster.get_rados_ioctx(pool_name).unwrap(); | ||
|
||
println!("Creating rados striper"); | ||
let rados_striper = ioctx.get_rados_striper().unwrap(); | ||
|
||
println!("Getting test object stat"); | ||
let (size, _) = rados_striper.rados_object_stat(object_name).unwrap(); | ||
|
||
let mut read_buf = vec![0; size as usize]; | ||
|
||
println!("Reading test object"); | ||
rados_striper.rados_object_read(object_name, &mut read_buf, 0).unwrap(); | ||
|
||
let read_buf_str = str::from_utf8(&read_buf).unwrap(); | ||
|
||
assert_eq!(read_buf_str, "lorem ipsum"); | ||
} | ||
|
||
println!("Deleting pool {}", pool_name); | ||
cluster.rados_delete_pool(pool_name).unwrap(); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,95 @@ | ||
# | ||
# Copyright (C) 2013,2014 Loic Dachary <loic@dachary.org> | ||
# | ||
# This program is free software: you can redistribute it and/or modify | ||
# it under the terms of the GNU Affero General Public License as published by | ||
# the Free Software Foundation, either version 3 of the License, or | ||
# (at your option) any later version. | ||
# | ||
# This program is distributed in the hope that it will be useful, | ||
# but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
# GNU Affero General Public License for more details. | ||
# | ||
# You should have received a copy of the GNU Affero General Public License | ||
# along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
# | ||
set -e | ||
set -x | ||
set -u | ||
|
||
DIR=${1} | ||
|
||
# reset | ||
pkill ceph || true | ||
rm -rf ${DIR}/* | ||
LOG_DIR=${DIR}/log | ||
MON_DATA=${DIR}/mon | ||
MDS_DATA=${DIR}/mds | ||
MOUNTPT=${MDS_DATA}/mnt | ||
OSD_DATA=${DIR}/osd | ||
mkdir ${LOG_DIR} ${MON_DATA} ${OSD_DATA} ${MDS_DATA} ${MOUNTPT} | ||
MDS_NAME="Z" | ||
MON_NAME="a" | ||
MGR_NAME="x" | ||
|
||
# cluster wide parameters | ||
cat >> ${DIR}/ceph.conf <<EOF | ||
[global] | ||
fsid = $(uuidgen) | ||
osd crush chooseleaf type = 0 | ||
run dir = ${DIR}/run | ||
auth cluster required = none | ||
auth service required = none | ||
auth client required = none | ||
osd pool default size = 1 | ||
[mds.${MDS_NAME}] | ||
host = localhost | ||
[mon.${MON_NAME}] | ||
log file = ${LOG_DIR}/mon.log | ||
chdir = "" | ||
mon cluster log file = ${LOG_DIR}/mon-cluster.log | ||
mon data = ${MON_DATA} | ||
mon addr = 127.0.0.1 | ||
mon allow pool delete = true | ||
[osd.0] | ||
log file = ${LOG_DIR}/osd.log | ||
chdir = "" | ||
osd data = ${OSD_DATA} | ||
osd journal = ${OSD_DATA}.journal | ||
osd journal size = 100 | ||
osd objectstore = memstore | ||
osd class load list = * | ||
osd class default list = * | ||
EOF | ||
|
||
export CEPH_CONF=${DIR}/ceph.conf | ||
|
||
# start an osd | ||
ceph-mon --id ${MON_NAME} --mkfs --keyring /dev/null | ||
touch ${MON_DATA}/keyring | ||
ceph-mon --id ${MON_NAME} | ||
|
||
# start an osd | ||
OSD_ID=$(ceph osd create) | ||
ceph osd crush add osd.${OSD_ID} 1 root=default host=localhost | ||
ceph-osd --id ${OSD_ID} --mkjournal --mkfs | ||
ceph-osd --id ${OSD_ID} | ||
|
||
# start a manager | ||
ceph-mgr --id ${MGR_NAME} | ||
|
||
# test the setup | ||
ceph --version | ||
ceph status | ||
test_pool=$(uuidgen) | ||
temp_file=$(mktemp) | ||
ceph osd pool create ${test_pool} 0 | ||
rados --pool ${test_pool} put group /etc/group | ||
rados --pool ${test_pool} get group ${temp_file} | ||
diff /etc/group ${temp_file} | ||
ceph osd pool delete ${test_pool} ${test_pool} --yes-i-really-really-mean-it | ||
rm ${temp_file} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
#!/bin/bash | ||
|
||
set -e | ||
|
||
rm -rf /tmp/ceph | ||
mkdir /tmp/ceph | ||
/micro-osd.sh /tmp/ceph | ||
export CEPH_CONF=/tmp/ceph/ceph.conf | ||
|
||
set +e |
Oops, something went wrong.