Skip to content

Latest commit

 

History

History
107 lines (87 loc) · 4.74 KB

ARTS17-1028.md

File metadata and controls

107 lines (87 loc) · 4.74 KB

ARTS17-20181028

Algorithm: Remove Element

Review: What is the Java 9 Module System?

Tip: Mycat 原理

Share: 近期学习kafka和分库分表的一些感受

Algorithm

package org.nocoder.leetcode.solution;

/**
 * 27.Remove Element
 *
 * Given an array nums and a value val, remove all instances of that value in-place and return the new length.
 *
 * Do not allocate extra space for another array, you must do this by modifying the input array in-place with O(1) extra memory.
 *
 * The order of elements can be changed. It doesn't matter what you leave beyond the new length.
 *
 * Example 1:
 *
 * Given nums = [3,2,2,3], val = 3,
 *
 * Your function should return length = 2, with the first two elements of nums being 2.
 *
 * It doesn't matter what you leave beyond the returned length.
 * Example 2:
 *
 * Given nums = [0,1,2,2,3,0,4,2], val = 2,
 *
 * Your function should return length = 5, with the first five elements of nums containing 0, 1, 3, 0, and 4.
 *
 * Note that the order of those five elements can be arbitrary.
 *
 * It doesn't matter what values are set beyond the returned length.
 * Clarification:
 *
 * Confused why the returned value is an integer but your answer is an array?
 *
 * Note that the input array is passed in by reference, which means modification to the input array will be known to the caller as well.
 *
 * Internally you can think of this:
 *
 * // nums is passed in by reference. (i.e., without making a copy)
 * int len = removeElement(nums, val);
 *
 * // any modification to nums in your function would be known by the caller.
 * // using the length returned by your function, it prints the first len elements.
 * for (int i = 0; i < len; i++) {
 *     print(nums[i]);
 * }
 * @author jason
 * @date 2018/10/28.
 */
public class RemoveElement {
    public static int removeElement(int[] nums, int val) {
        if(nums == null || nums.length == 0){
            return 0;
        }
        int len = 0;

        for (int i = 0; i < nums.length ; i++) {
            if(nums[i] != val){
                nums[len] = nums[i];
                len ++;
            }
        }
        return len;
    }

    public static void main(){
        int[] nums = new int[]{3, 2, 2, 3};
        int val = 2;
        removeElement(nums, val);
    }
}

Review

What is the Java 9 Module System?

https://medium.com/@nagillavenkatesh1234/what-is-the-java-9-module-system-2d07bfa00abf

Tip

Mycat 是什么?从定义和分类来看,它是一个开源的分布式数据库系统,是一个实现了 MySQL 协议的的 Server,前端用户可以把它看作是一个数据库代理,用 MySQL 客户端工具和命令行访问,而其后端可以用 MySQL 原生(Native)协议与多个 MySQL 服务器通信,也可以用 JDBC 协议与大多数主流数据库服务器通信, 其核心功能是分表分库,即将一个大表水平分割为 N 个小表,存储在后端 MySQL 服务器里或者其他数据库里。

Mycat 的原理中最重要的一个动词是“拦截”,它拦截了用户发送过来的 SQL 语句,首先对 SQL 语句做了 一些特定的分析:如分片分析、路由分析、读写分离分析、缓存分析等,然后将此 SQL 发往后端的真实数据库, 并将返回的结果做适当的处理,最终再返回给用户。

Share

分享一下我最近在项目中运用kafka和学习分库分表的一些感受。

我认为学习一项新的技术不是难点,难点在于和目前业务的结合,也就是如何解决实际问题。越来越深刻的感受到技术不能脱离业务,也没有完美的解决方案,如果认为我们的解决方案没有问题,那只是暂时没有发现而已。我们要找出更好的,更符合解决现状问题的方案,平衡各种方案的优劣势,从而更好的解决问题。

为什么要用消息中间件,目的就是解耦。我们的子系统越来越多,各子系统之间的调用也越来越多,使用消息中间件可以更好的解决各个系统之间的依赖。并且后续访问量大了以后,可以使用消息中间件来做限流。

为什么考虑分库分表,目前项目使用单库mysql存储数据,有部分表的数量达到了600多万,查询效率比较低,最近业务发展趋势比较好,后续这些表的数据可能会成倍增长,根据网上看的经验值,500万到1000万就要考虑是否分库分表。于是开始研究分库分表的东西,真的是不看不知道,一看吓一跳,要准备的东西太多了,分哪些表,按什么规则分,数据往那些表存,哪些需要存nosql数据库,分片数据查询,分布式事务。初步使用mycat数据库中间件来做个测试,目前刚了解了一点皮毛。想到前面那么多坑要踩,还是有点发憷哦。