Skip to content

Commit

Permalink
Chore: refine build-platform-specific.sh
Browse files Browse the repository at this point in the history
  • Loading branch information
drmingdrmer committed Dec 18, 2023
1 parent 8742e1d commit c90cdec
Show file tree
Hide file tree
Showing 2 changed files with 70 additions and 115 deletions.
6 changes: 3 additions & 3 deletions _src/openraft-read/2023-12-17-openraft-read.md
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ excerpt: "Openraft 中对 linearizable read 流程的优化"
也就是说 `(Term_0, index_0)` 这条 log 是 `read_0` 看到的最后一条 log.
那么其中的 `Term_0` 就有3种情况:

- **case-gt**: `Term_0 > Term_1`:
- **case-gt**: `Term_0 > Term_1`:

为避免这种不可处理的情况发生, Leader 在时间 `t` 向一个 quorum 发 heartbeat 请求, 以确认在时间范围 `(0, t)` 内都没有更高的 Term;

Expand All @@ -76,9 +76,9 @@ excerpt: "Openraft 中对 linearizable read 流程的优化"

在这种情况下要保证 linearizable read, 就要求 `read_1` 读时的 StateMachine 至少要包含到 `NoopIndex` 的 log.

- **case-eq**: `Term_0 == Term_1`:
- **case-eq**: `Term_0 == Term_1`:

对这种情况, 读操作 `read_0` 一定是在当前 node 执行的读操作;
对这种情况, 读操作 `read_0` 一定是在当前 node 执行的读操作;

我们又知道由于 Raft 协议规定只有已经 commit 的 log 才能被读取, 所以 `read_0` 读到的数据一定是当前 CommitIndex 之前的, 即 `index_0 <= CommitIndex`;

Expand Down
179 changes: 67 additions & 112 deletions build-platform-specific.sh
Original file line number Diff line number Diff line change
@@ -1,32 +1,20 @@
#!/bin/sh

# fn="$(ls _posts/*$1* | head -n1)"

# if [ "$fn." = "." ]; then
# echo "Usage: $0 <fn_pattern>"
# exit 1
# fi


# === Build for copying to other platform only ===
#
# It looks like gitee no longer support external access with refer
# --repo git@gitee.com:drdrxp/bed.git@openacid-$platform-import-assets \

# for platform in wechat simple; do
# md2zhihu \
# -r git@gitee.com:drdrxp/bed.git@openacid \
# -p $platform \
# --keep-meta \
# --code-width 600 \
# $fn \
# -o ${fn%.md}-$platform.md
set -o errexit

# done
# for example:
# https://pub-e254240c5c35410cb21a0cf4fb58f73e.r2.dev/2023-12-17-openraft-read.html
url_base="https://pub-e254240c5c35410cb21a0cf4fb58f73e.r2.dev"


# === Build for copying to other platform only ===
#
# The assets do not need to be kept after publishing on other platforms.

# Call xp-md2html to convert md to html, using github-markdown.css
# xp-md2html is my local rust repo
# xp-md2html is a personal repo
md2html()
{
local src_path="$1"
Expand All @@ -36,7 +24,6 @@ md2html()

{
cat <<-END
<!doctype html>
<html>
<head>
Expand All @@ -63,7 +50,6 @@ md2html()
<article class="markdown-body">
END

# skip '---'
cat "$src_path" | xp-md2html

cat <<-END
Expand All @@ -76,94 +62,63 @@ END
} > "$output_path"
}

# for example:
# https://pub-e254240c5c35410cb21a0cf4fb58f73e.r2.dev/2023-12-17-openraft-read.html
url_base="https://pub-e254240c5c35410cb21a0cf4fb58f73e.r2.dev"



fn=_src/openraft-read/2023-12-17-openraft-read.md
name=${fn##*/}
name=${name%.md}
title=${name#20??-??-??-}

echo "fn: $fn"
echo "name: $name"
echo "title: $title"


# Build local markdown
mkdir -p md2-local

# reference local resource
platform=wechat
md2zhihu \
--platform $platform \
--code-width 600 \
--refs _data/refs.yml \
--output-dir ./md2-local \
--asset-output-dir ./md2-local/ \
--md-output ./md2-local/$name.md \
$fn

# reference remote resource
md2zhihu \
--platform $platform \
--code-width 600 \
--refs _data/refs.yml \
--output-dir ./md2-local \
--asset-output-dir ./md2-local/ \
--md-output ./md2-local/$name-remote.md \
--rewrite "^$title/" "$url_base/$title/" \
$fn

cp assets/images/qrcode-hori.jpg ./md2-local/
cp assets/css/github-markdown.css ./md2-local/

# Build html
md2html "./md2-local/$name.md" "./md2-local/$name.html"
md2html "./md2-local/$name-remote.md" "./md2-local/$name-remote.html"

# Upload
aws s3 sync ./md2-local/ s3://bed/

echo ""
echo "$url_base/$name.html"
echo "$url_base/$name-remote.html"

exit 0

# Build zhihu specific md
#
# Usage: import md to zhihu

platform=zhihu
md2zhihu \
--platform $platform \
--code-width 600 \
--refs _data/refs.yml \
--output-dir ./md2-$platform \
--asset-output-dir ./md2-$platform/ \
--md-output ./md2-$platform/ \
--repo git@gitee.com:drdrxp/bed.git@openacid-$platform-import-assets \
$fn


# Build wechat specific html.
# Render it to the last article.
#
# Usage: push and let github build it and copy the html on a browser.

platform=wechat
md2zhihu \
--platform $platform \
--code-width 600 \
--refs _data/refs.yml \
--keep-meta \
--output-dir ./md2-$platform \
--asset-output-dir ./md2-$platform/ \
--md-output ./_posts/2000-01-01-wechat-import.md \
--repo git@gitee.com:drdrxp/bed.git@openacid-$platform-import-assets \
$fn

build()
{
local platform="$1"
local fn="$2"

local name_suffix=${fn##*/}
local name=${name_suffix%.md}
# remove date
local title=${name#20??-??-??-}

echo ""
echo "fn: $fn"
echo "name: $name"
echo "title: $title"
echo ""

# Build local markdown
mkdir -p md2-local

# reference local resource
md2zhihu \
--platform $platform \
--code-width 600 \
--refs _data/refs.yml \
--output-dir ./md2-local \
--asset-output-dir ./md2-local/ \
--md-output ./md2-local/$name-$platform.md \
$fn

# reference remote resource
md2zhihu \
--platform $platform \
--code-width 600 \
--refs _data/refs.yml \
--output-dir ./md2-local \
--asset-output-dir ./md2-local/ \
--md-output ./md2-local/$name-$platform-remote.md \
--rewrite "^$title/" "$url_base/$title/" \
$fn

cp assets/images/qrcode-hori.jpg ./md2-local/
cp assets/css/github-markdown.css ./md2-local/

# Build html
md2html "./md2-local/$name-$platform.md" "./md2-local/$name-$platform.html"
md2html "./md2-local/$name-$platform-remote.md" "./md2-local/$name-$platform-remote.html"

# Upload
aws s3 sync ./md2-local/ s3://bed/

echo "Built online md:"
echo ""
echo " $url_base/$name-$platform.html"
echo " $url_base/$name-$platform-remote.html"
echo ""
}

build "wechat" _src/openraft-read/2023-12-17-openraft-read.md
build "wechat" _src/openraft-read/raft-read-proof.md

0 comments on commit c90cdec

Please sign in to comment.