cassandra - cql

语法

CQL

Datacenter

1
2
use system;
select data_center from local;

Role / User

创建

1
2
3
4
5
CREATE ROLE [IF NOT EXISTS] role_name 
[WITH SUPERUSER = true | false
| LOGIN = true | false
| PASSWORD = 'password'
| OPTIONS = option_map]

示例

1
2
CREATE ROLE IF NOT EXISTS 'root' WITH SUPERUSER = true AND LOGIN = false;
CREATE ROLE IF NOT EXISTS 'root' WITH SUPERUSER = true AND PASSWORD = 'root';

修改权限

1
2
3
4
5
ALTER ROLE role_name 
[WITH [PASSWORD = 'password']
[LOGIN = true | false]
[SUPERUSER = true | false]
[OPTIONS = map_literal]]

示例

1
ALTER ROLE root WITH PASSWORD = 'NewPassword';

Key Space

查询

1
2
# 列出所有 keysapces
desc keyspaces;

创建

1
2
3
4
5
6
7
CREATE  KEYSPACE [IF NOT EXISTS] keyspace_name 
WITH REPLICATION = {
'class' : 'SimpleStrategy', 'replication_factor' : N }
| 'class' : 'NetworkTopologyStrategy',
'dc1_name' : N [, ...]
}
[AND DURABLE_WRITES = true|false] ;

示例

1
2
3
4
CREATE  KEYSPACE IF NOT EXISTS "trace" WITH REPLICATION = {
'class' : 'NetworkTopologyStrategy',
'vg' : 2
}

Table

查询

1
desc <keyspace-name>;
1
2
use <keyspace-name>;
desc tables;

创建

1
2
3
4
5
6
7
CREATE TABLE [IF NOT EXISTS] [keyspace_name.]table_name ( 
column_definition [, ...]
PRIMARY KEY (column_name [, column_name ...])
[WITH table_options
| CLUSTERING ORDER BY (clustering_column_name order])
| ID = 'table_hash_tag'
| COMPACT STORAGE]

数据类型参考这里

删除

1
DROP TABLE [IF EXISTS] keyspace_name.table_name

修改

添加列

1
2
3
4
5
6
ALTER TABLE [keyspace_name.] table_name 
[ALTER column_name TYPE cql_type]
[ADD (column_definition_list)]
[DROP column_list | COMPACT STORAGE ]
[RENAME column_name TO column_name]
[WITH table_properties];

示例

1
ALTER TABLE trace.ranker ADD rid TEXT;

Query

1
2
3
// 查询一条
select * from ks.table limit 1;
select * from ks.table where id='value' limit 1;

kudu - usage

安装

新版本安装参考这里

centos

build

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
#!/bin/bash
sudo yum -y install autoconf automake curl cyrus-sasl-devel cyrus-sasl-gssapi \
cyrus-sasl-plain flex gcc gcc-c++ gdb git java-1.8.0-openjdk-devel \
krb5-server krb5-workstation libtool make openssl-devel patch pkgconfig \
redhat-lsb-core rsync unzip vim-common which
sudo yum -y install centos-release-scl-rh
sudo yum -y install devtoolset-8
git clone https://github.com/apache/kudu
cd kudu
build-support/enable_devtoolset.sh thirdparty/build-if-necessary.sh
mkdir -p build/release
cd build/release
../../build-support/enable_devtoolset.sh \
../../thirdparty/installed/common/bin/cmake \
-DCMAKE_BUILD_TYPE=release \
../..
make -j4

对于 centos 7 默认 gcc 是 4.8,用 yum install gcc72-c++ 升级到 gcc-g++ 7.2

package

1
2
3
4
# 下载 repo 配置
$ wget http://archive.cloudera.com/kudu/redhat/7/x86_64/kudu/cloudera-kudu.repo -P /etc/yum.repos.d/
# 安装
$ yum update & yum install kudu

linux - crontab

命令格式

1
2
3
MIN HOUR DOM MON DOW CMD
# DOM: day of month
# DOW: day of week

查看

1
$ crontab -l

编辑

1
$ crontab -e

启动时运行

1
@reboot /home/ubuntu/app/consul/start.sh

时间格式

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
MIN HOUR DOM MON DOW CMD
* * * * * ...

# 特殊符号
* 任意值
, 多值分隔符
- 范围分隔符
/ 间隔符 (step values)

# 示例
* * * * * 每分钟
30 08 10 06 * 每年的 6 月 10 号 8 点 30 分
30 * * * * 每小时的 30 分
00 11,16 * * * 每天的 11:00 和 16:00
00 09-18 * * * 每天的 9、10 ... 18 点 00 分
00 09-18 * * 1-5 周一至周五每天的 9、10 ... 18 点 00 分
*/10 * * * * 每十分钟

设置 PATH

1
2
$ crontab -e # 开头添加如下内容
PATH=/bin:/sbin:/usr/bin:/usr/sbin:/home/ubuntu/.local/bin

python - generate wheel

安装

1
$ pip3 install wheel setuptools

创建 setup.py

1
2
3
4
5
6
7
from setuptools import setup

setup(
name='abtest',
version='1.0',
packages=['.abtest'],
)

setup.py 示例

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
import os.path

from setuptools import setup

REQUIREMENTS = 'requirements.txt'
requires = []
if os.path.isfile(REQUIREMENTS):
with open(REQUIREMENTS, 'r') as f:
requires = f.read().splitlines()

# VERSION i.e. 1.3
with open('VERSION', 'r') as f:
v = f.read()
setup(
name='abtest',
version=v.strip(),
packages=['abtest', 'data', 'model', 'utils'], # 指定 package
install_requires=requires # 指定依赖基本版本
)

打包工程

1
python setup.py bdist_wheel --universal

c++ compiler

指定编译器

1
2
3
4
5
export PATH=/opt/scylladb/bin:$PATH
export LD_LIBRARY_PATH=/opt/scylladb/lib64:$LD_LIBRARY_PATH
export LD_LIBRARY_PATH=/opt/scylladb/lib:$LD_LIBRARY_PATH
export CC=/opt/scylladb/bin/gcc
export CXX=/opt/scylladb/bin/g++

编译选项

1
2
3
4
5
6
# warning
-Wall 开启警告(all: 应该开启的最小警告集合)
-Wextra 开启扩展警告
-Werror 所有警告视为错误
-Wno-error=... 关闭某项警告视为错误
-Wno-<...> 关闭某项警告视为错误

附录

-Wall

1
2
3
4
5
6
7
8
9
-Waddress -Warray-bounds (only with -O2) -Wc++0x-compat -Wchar-subscripts
-Wenum-compare (in C/Objc; this is on by default in C++) -Wimplicit-int (C and
Objective-C only) -Wimplicit-function-declaration (C and Objective-C only)
-Wcomment -Wformat -Wmain (only for C/ObjC and unless -ffreestanding)
-Wmissing-braces -Wnonnull -Wparentheses -Wpointer-sign -Wreorder -Wreturn-type
-Wsequence-point -Wsign-compare (only in C++) -Wstrict-aliasing
-Wstrict-overflow=1 -Wswitch -Wtrigraphs -Wuninitialized -Wunknown-pragmas
-Wunused-function -Wunused-label -Wunused-value -Wunused-variable
-Wvolatile-register-var

-Wextra

1
2
3
4
-Wclobbered -Wempty-body -Wignored-qualifiers -Wmissing-field-initializers
-Wmissing-parameter-type (C only) -Wold-style-declaration (C only) -Woverride-init
-Wsign-compare -Wtype-limits -Wuninitialized -Wunused-parameter (only with -Wunused
or -Wall) -Wunused-but-set-parameter (only with -Wunused or -Wall)

warn 示例配置

1
-Wall -Wextra -Waggregate-return -Wcast-align -Wcast-qual -Wdisabled-optimization -Wdiv-by-zero -Wendif-labels -Wformat-extra-args -Wformat-nonliteral -Wformat-security -Wformat-y2k -Wimplicit -Wimport -Winit-self -Winline -Winvalid-pch -Wjump-misses-init -Wlogical-op -Werror=missing-braces -Wmissing-declarations -Wno-missing-format-attribute -Wmissing-include-dirs -Wmultichar -Wpacked -Wpointer-arith -Wreturn-type -Wsequence-point -Wsign-compare -Wstrict-aliasing -Wstrict-aliasing=2 -Wswitch -Wswitch-default -Werror=undef -Wno-unused -Wvariadic-macros -Wwrite-strings -Wc++-compat -Werror=declaration-after-statement -Werror=implicit-function-declaration -Wmissing-prototypes -Werror=nested-externs -Werror=old-style-definition -Werror=strict-prototypes

内存泄漏排查

简述

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
$ pid=$(pgrep ranker_service)
$ pmap -x $pid
9085: ./bin/ranker_service --cloud_region=aws-se --gray_cloud_list=none
Address Kbytes RSS Dirty Mode Mapping
0000000000400000 19180 7236 0 r-x-- ranker_service
00000000018bb000 280 168 24 r---- ranker_service
0000000001901000 92 40 40 rw--- ranker_service
0000000001918000 212 120 120 rw--- [ anon ]
0000023412800000 262144 216280 216280 rw--- [ anon ]
000002342f000000 528384 524292 524292 rw--- [ anon ]
0000023453800000 262144 262144 262144 rw--- [ anon ]
0000023469c00000 262144 262144 262144 rw--- [ anon ]
0000023486000000 262144 262144 262144 rw--- [ anon ]
00000234aec00000 524288 518296 518296 rw--- [ anon ]
00000234db400000 262144 150220 150220 rw--- [ anon ]
0000023546400000 23330816 23188160 23188160 rw--- [ anon ]
0000023b50400000 303104 294920 294920 rw--- [ anon ]
0000023b69000000 475136 458768 458768 rw--- [ anon ]
...
$ gcore $pid

dump

1
2
3
4
5
6
7
8
$ gdb bin/ranker_service core.9085
(gdb) dump binary memory result.bin 0x23546400000 0x23586400000 # dump 1G 内存数据

## dump 内存块 0x23546400000 全部数据
# 计算地址
> hex(0x0000023546400000 + 23330816 * 1024) # python3
'0x23ad6400000'
(gdb) dump binary memory result.bin 0x23546400000 0x23ad6400000 # dump 区块全部数据 23330816KB

统计 vtable

1
2
$ hexdump result.bin | awk '{printf "%s%s%s%s\n%s%s%s%s\n", $5,$4,$3,$2,$9,$8,$7,$6}' | sort | uniq -c | sort -nr  > hex.t
$ hexdump core.9085 | awk '{printf "%s%s%s%s\n%s%s%s%s\n", $5,$4,$3,$2,$9,$8,$7,$6}' | sort | uniq -c | sort -nr | head

image-20220613180006614

image-20220613180039586

参考