Skip to content

Instantly share code, notes, and snippets.

View leewin12's full-sized avatar

greg.lee leewin12

View GitHub Profile
@leewin12
leewin12 / mysql-remote-backup.sql
Last active November 5, 2021 12:27
Backup limited rows with `REPLACE` instead of `INSERT` via mysqldump (MySQL 5.7)
#!/bin/bash
#
# How to restore?
# $ zcat backup.sql.gz | mysql -h{} -u{} -p --database {dbname}
#
# --set-gtid-purged=OFF → https://stackoverflow.com/a/49059063/1378965
# --column-statistics=OFF → https://serverfault.com/a/912677/538646
# --single-transaction → https://dev.mysql.com/doc/refman/5.7/en/mysqldump.html#option_mysqldump_single-transaction
# --no-create-db → https://dev.mysql.com/doc/refman/5.7/en/mysqldump.html#option_mysqldump_no-create-db
# --skip-add-drop-table → https://dev.mysql.com/doc/refman/5.7/en/mysqldump.html#option_mysqldump_add-drop-table
$ netsh int ipv4 add excludedportrange protocol=tcp startport=2375 numberofports=1
@leewin12
leewin12 / how-to-reset-kafka-offset.txt
Created June 23, 2020 08:42
how-to-reset-kafka-offset
offset reset (0.8.2 기준)
topic을 지워봐야 zookeeper에 보존된 low-level offset을 초기화 할 수 없음.
따라서 zookeeper shell에 접근해서 low-level offset을 초기화해야함.
[root@sv-kafka-dev01 bin]# ./zookeeper-shell.sh sv-zkdev1a.idincu.net:2181/kafka
Connecting to sv-zkdev1a.idincu.net:2181/kafka
ls /consumers
def testScreenshot() {
System.setProperty("webdriver.chrome.driver", "C:\\Users\\Greg\\Downloads\\chromedriver79.exe")
new File("screenshot.png").withOutputStream {
ChromeOptions options = new ChromeOptions()
options.headless = true
WebDriver driver = new ChromeDriver(ChromeDriverService.createDefaultService(), options)
try {
driver.get("https://www.google.com")
it.write(driver.getScreenshotAs(OutputType.BYTES))
} finally {
@leewin12
leewin12 / how-to-extend-lvm.sh
Last active October 7, 2019 07:47
CentOS_6/7 lvm 추가하는 방법
0. lvm 설치
$ yum install lvm2 -y
1. 디스크 먼저 추가
(/dev/xvdb 라고 가정)
2. fdisk 로 해당 디스크 파티셔닝 및 파일시스템을 Linux LVM (8e) 타입으로 변경
$ fdisk /dev/xvdb
Device contains neither a valid DOS partition table, nor Sun, SGI or OSF disklabel
Building a new DOS disklabel with disk identifier 0xe866154b.
@leewin12
leewin12 / jpa-mysql-json.java
Last active September 7, 2022 14:10
Build JPA 2.0 CriteriaQuery with MySQL JSON column
CriteriaBuilder cb = new CriteriaBuilder();
// = SELECT * FROM entity WHERE JSON_EXTRACT("json_column", "$.path")
Root<entity> root;
cb.equal(
cb.function("JSON_EXTRACT", Integer.class, root.get("json_column"), "$.path"),
100);
@leewin12
leewin12 / mysql.service
Created September 6, 2019 13:01
Percona MySQL 5.7.x limits config
$ vim /etc/systemd/system/mysql.service
[Service]
LimitNOFILE = infinity
LimitCore = infinity
LimitMEMLOCK = infinity
$ systemctl daemon-reload
$ service mysql restart
$ ps -ef | grep mysql | awk '{print $2}' | head -n1 | xargs -I{} cat /proc/{}/limits
@leewin12
leewin12 / my.cnf
Last active October 15, 2019 07:27
Percona MySQL 5.7.x my.cnf 2core / 8G
[client]
default-character-set = utf8mb4
no-auto-rehash # faster cli interaction but no autocomplete
show-warnings # show warnings when it happens
prompt=\u@\h:\d\_\R:\m:\\s> # make cli prompt better ex) root@localhost:(profile) 17:08:55>
pager="less -n -i -F -X -E" # using less for long result rows
[mysqld]
# default
character-set-server = utf8mb4
@leewin12
leewin12 / jvm-launch.sh
Created July 17, 2019 02:42
jvm config and nohup without nohup.out
nohup java -jar {{ jvm_config }} -verbose:gc -XX:+UseG1GC -XX:+PrintGCDetails -XX:+PrintGCDateStamps -XX:MetaspaceSize=100M -XX:MaxMetaspaceSize=100M -Xloggc:logs/gc.log -XX:NumberOfGCLogFiles=4 -XX:GCLogFileSize=1M -XX:+UseGCLogFileRotation -Dspring.profiles.active={{ BUILD_PROFILE }} -Dfile.encoding=utf-8 {{ project_name }}.jar 1>/dev/null 2> >(exec nohup logger -t {{ project_name }}) &
@leewin12
leewin12 / spring-tx-rollback.md
Created December 21, 2018 07:30
Spring transaction의 rollback 처리에 대한 주의사항 정리

요약 @Transactional 처리가 필요한 메소드는, 해당 메소드 내에서 사용되는 모든 메소드에 명시적으로 @Transactional을 처리해주는게 안전하다.

이하 내용

  • Spring JDK Dynamic Proxy는 proxy 처리가 필요가 없거나 (@transactional등), 따로 옵션을 켜주지 않는 한, proxy obj를 만들지 않는다.

  • 따라서 proxy가 없는 class에 대해서는 당연히 tx 영역으로 잡히지 않고, proxy가 없는 외부 class의 method 호출 결과에 대해 try/catch 처리를 할 경우, spring tx manger는 rollback을 하지 않습니다.

  • proxy가 있는 경우에도, 외부 class의 method를 @transactional 없이 호출 할 경우, transactionl이 none으로 인식되어, 호출 결과에 대해 try/catch 처리를 할 경우, spring tx manger는 rollback을 하지 않습니다.