Skip to content

Instantly share code, notes, and snippets.

@ttfcfc
ttfcfc / AbstractJdbcRepository.java
Created January 8, 2020 01:55 — forked from criminy/AbstractJdbcRepository.java
Implementation of PagingAndSortingRepository using JdbcTemplate
import java.io.Serializable;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import org.springframework.data.domain.Sort;
@ttfcfc
ttfcfc / 当当sharding-jdbc分布式Id生成器.md
Created March 22, 2018 09:56 — forked from yangl/当当sharding-jdbc分布式Id生成器.md
当当sharding-jdbc分布式Id生成器 详见:http://shardingjdbc.io/docs/02-guide/key-generator/ 注意该实现使用限止:1.每毫秒最大并发4096;2.最久使用至2156年 ;

分布式Id生成器

实现动机

传统数据库软件开发中,主键自动生成技术是基本需求。而各大数据库对于该需求也提供了相应的支持,比如MySQL的自增键。 对于MySQL而言,分库分表之后,不同表生成全局唯一的Id是非常棘手的问题。因为同一个逻辑表内的不同实际表之间的自增键是无法互相感知的, 这样会造成重复Id的生成。我们当然可以通过约束表生成键的规则来达到数据的不重复,但是这需要引入额外的运维力量来解决重复性问题,并使框架缺乏扩展性。

目前有许多第三方解决方案可以完美解决这个问题,比如UUID等依靠特定算法自生成不重复键,或者通过引入Id生成服务等。 但也正因为这种多样性导致了Sharding-JDBC如果强依赖于任何一种方案就会限制其自身的发展。

@ttfcfc
ttfcfc / TiDB碎碎念.md
Created March 22, 2018 09:46 — forked from yangl/TiDB碎碎念.md
TiDB整理

遗留数据同步方案(Loader + Syncer)具体方案如下:

使用 Mydumper + TiDB Loader 全量导出 MySQL 库中数据,并记录 SavePoint,然后导入 TiDB。 使用 TiDB Syncer 做实时增量同步,将 MySQL 中数据同步到 TiDB。

将 MyCAT 中按月拆分的表通过 ETL 以无主键的形式导回 MySQL 单表( MyCAT 分表中存在主键重复,不能单纯直接导入 TiDB,并且当时 TiDB 对于 ETL 工具的支持还未完善,无法使用 ETL工具导入 TiDB),只保留当前月份数据不导入。

将重新整合后的 MySQL 单表数据通过 Mydumper + TiDB Loader 导入 TiDB。

待上线当天晚上,将当前月份数据导回 MySQL(重建主键),再通过 Mydumper + TiDB Loader 导入TiDB。

@ttfcfc
ttfcfc / nginx-tuning.md
Created March 22, 2018 06:47 — forked from denji/nginx-tuning.md
NGINX tuning for best performance

NGINX Tuning For Best Performance

For this configuration you can use web server you like, i decided, because i work mostly with it to use nginx.

Generally, properly configured nginx can handle up to 400K to 500K requests per second (clustered), most what i saw is 50K to 80K (non-clustered) requests per second and 30% CPU load, course, this was 2 x Intel Xeon with HyperThreading enabled, but it can work without problem on slower machines.

You must understand that this config is used in testing environment and not in production so you will need to find a way to implement most of those features best possible for your servers.

@ttfcfc
ttfcfc / nginx.conf
Created March 22, 2018 06:45 — forked from plentz/nginx.conf
Best nginx configuration for improved security(and performance). Complete blog post here http://tautt.com/best-nginx-configuration-for-security/
# to generate your dhparam.pem file, run in the terminal
openssl dhparam -out /etc/nginx/ssl/dhparam.pem 2048
@ttfcfc
ttfcfc / ShortUrl.java
Created November 30, 2017 10:44 — forked from binjoo/ShortUrl.java
JAVA:短地址压缩算法原理解析
import java.security.MessageDigest;
import java.security.NoSuchAlgorithmException;
/**
* 【转】URL短地址压缩算法 微博短地址原理解析
* http://www.cnblogs.com/jinzhao/archive/2012/04/08/2437188.html
*
*/
public class ShortUrl {
public static String[] generateCode(String url) {
@ttfcfc
ttfcfc / UmpLogAspect.java
Created January 12, 2017 03:48 — forked from yangl/UmpLogAspect.java
UmpLog切面,不用侵入代码一个一个的添加UMP监控。注意:如果把spring mvc的Controller 作为切入点,下边的xml配置必须和springmvc-servlet.xml放一起,不然不起作用!!!
package com.jd.buy.giftshop.shared.utils.aspect;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Map;
import java.util.Set;
import javax.annotation.PostConstruct;
import org.aspectj.lang.ProceedingJoinPoint;
@ttfcfc
ttfcfc / BlackFilterAspect.java
Created January 12, 2017 03:48 — forked from yangl/BlackFilterAspect.java
黑名单过滤器,启动一个线程定时同步远程redis黑名单数据至本地JVM内存;
package com.jd.couponservice.service.aspect;
import java.util.HashSet;
import java.util.Set;
import java.util.concurrent.Executors;
import java.util.concurrent.ScheduledExecutorService;
import java.util.concurrent.TimeUnit;
import javax.annotation.Resource;
@ttfcfc
ttfcfc / LogAspect.java
Created January 12, 2017 03:48 — forked from yangl/LogAspect.java
调用api接口超时打印日志;
package com.jd.couponservice.service.aspect;
import java.util.HashMap;
import java.util.Map;
import org.aspectj.lang.ProceedingJoinPoint;
import org.aspectj.lang.annotation.Around;
import org.aspectj.lang.annotation.Aspect;
import org.aspectj.lang.annotation.Pointcut;
import org.aspectj.lang.reflect.MethodSignature;
@ttfcfc
ttfcfc / PageList.java
Created January 12, 2017 03:48 — forked from yangl/PageList.java
分页器,来自webx。
package com.jd.couponept.couponeptadmin.common.util;
import java.io.Serializable;
import java.util.List;
/**
* Page查询结果对象
* @author YANGLiN
*/