zoukankan      html  css  js  c++  java
  • 关于 shazam 代理

    关于 shazam

    他是基于mysql的一个代理,import了PingCAP基于golang实现的sql parser
    代理需要做路由以及sharding,所以需要解析语法,但仅实现ast,不实现语义
    更多介绍去看他的官方git就可以了,写的总体还是不错的,性能我没做测试,后续安排此事

    他比较重要的一个数据结构resultset

    mysql/result.go
    
    // Resultset means mysql results of sql execution, included split table sql
    type Resultset struct {
      Fields     []*Field        // 解析协议后的mysql协议内field段
      FieldNames map[string]int  // column information, key: column name value: index in Fields
      Values     [][]interface{} // 解析协议后的mysql协议内的data段
    
      RowDatas []RowData // 原始mysql协议数据,上面三个字段都是parser,并不返回session中的客户端
                 // 返回客户端的是这个RowDatas
    }
    

    通过golang的调试器dlv调试数据

    dlv exec ./shazam-proxy 
    
    b writeResultset 停到这个断点,他返回mysql会话内协议数据
    
    [GIN-debug] GET    /api/proxy/ping           --> github.com/nooncall/shazam/proxy/server.(*AdminServer).ping-fm (2 handlers)
    [GIN-debug] PUT    /api/proxy/config/prepare/:name --> github.com/nooncall/shazam/proxy/server.(*AdminServer).prepareConfig-fm (2 handlers)
    [GIN-debug] PUT    /api/proxy/config/commit/:name --> github.com/nooncall/shazam/proxy/server.(*AdminServer).commitConfig-fm (2 handlers)
    [GIN-debug] PUT    /api/proxy/namespace/delete/:name --> github.com/nooncall/shazam/proxy/server.(*AdminServer).deleteNamespace-fm (2 handlers)
    [GIN-debug] GET    /api/proxy/config/fingerprint --> github.com/nooncall/shazam/proxy/server.(*AdminServer).configFingerprint-fm (2 handlers)
    [GIN-debug] GET    /api/proxy/stats/sessionsqlfingerprint/:namespace --> github.com/nooncall/shazam/proxy/server.(*AdminServer).getNamespaceSessionSQLFingerprint-fm (2 handlers)
    [GIN-debug] GET    /api/proxy/stats/backendsqlfingerprint/:namespace --> github.com/nooncall/shazam/proxy/server.(*AdminServer).getNamespaceBackendSQLFingerprint-fm (2 handlers)
    [GIN-debug] GET    /api/metric/metrics       --> github.com/gin-gonic/gin.WrapH.func1 (2 handlers)
    [GIN-debug] GET    /debug/pprof/             --> github.com/gin-gonic/gin.WrapF.func1 (2 handlers)
    [GIN-debug] GET    /debug/pprof/cmdline      --> github.com/gin-gonic/gin.WrapF.func1 (2 handlers)
    [GIN-debug] GET    /debug/pprof/profile      --> github.com/gin-gonic/gin.WrapF.func1 (2 handlers)
    [GIN-debug] POST   /debug/pprof/symbol       --> github.com/gin-gonic/gin.WrapF.func1 (2 handlers)
    [GIN-debug] GET    /debug/pprof/symbol       --> github.com/gin-gonic/gin.WrapF.func1 (2 handlers)
    [GIN-debug] GET    /debug/pprof/trace        --> github.com/gin-gonic/gin.WrapF.func1 (2 handlers)
    [GIN-debug] GET    /debug/pprof/block        --> github.com/gin-gonic/gin.WrapF.func1 (2 handlers)
    [GIN-debug] GET    /debug/pprof/goroutine    --> github.com/gin-gonic/gin.WrapF.func1 (2 handlers)
    [GIN-debug] GET    /debug/pprof/heap         --> github.com/gin-gonic/gin.WrapF.func1 (2 handlers)
    [GIN-debug] GET    /debug/pprof/mutex        --> github.com/gin-gonic/gin.WrapF.func1 (2 handlers)
    [GIN-debug] GET    /debug/pprof/threadcreate --> github.com/gin-gonic/gin.WrapF.func1 (2 handlers)
    [GIN-debug] GET    /debug/pprof/allocs       --> github.com/gin-gonic/gin.WrapF.func1 (2 handlers)
    

    没啥问题的化,已经正常启动了

    下面这段是mysql原始协议,这个文档在以下实现描述
    https://dev.mysql.com/doc/internals/en/com-query-response.html#packet-ProtocolText::Resultset

    (dlv) p r.Fields
    []*github.com/nooncall/shazam/mysql.Field len: 3, cap: 3, [
    	*{
    		Data: github.com/nooncall/shazam/mysql.FieldData len: 48, cap: 48, [3,100,101,102,4,116,101,115,116,4,98,111,111,107,4,98,111,111,107,7,112,117,98,108,105,115,104,7,112,117,98,108,105,115,104,12,33,0,96,0,0,0,253,0,0,0,0,0],
    		Schema: []uint8 len: 4, cap: 43, [116,101,115,116],
    		Table: []uint8 len: 4, cap: 38, [98,111,111,107],
    		OrgTable: []uint8 len: 4, cap: 33, [98,111,111,107],
    		Name: []uint8 len: 7, cap: 28, [112,117,98,108,105,115,104],
    		OrgName: []uint8 len: 7, cap: 20, [112,117,98,108,105,115,104],
    		Charset: 33,
    		ColumnLength: 96,
    		Type: 253,
    		Flag: 0,
    		Decimal: 0,
    		DefaultValueLength: 0,
    		DefaultValue: []uint8 len: 0, cap: 0, nil,},
    	*{
    		Data: github.com/nooncall/shazam/mysql.FieldData len: 48, cap: 48, [3,100,101,102,4,116,101,115,116,4,98,111,111,107,4,98,111,111,107,7,97,100,100,114,101,115,115,7,97,100,100,114,101,115,115,12,33,0,96,0,0,0,253,0,0,0,0,0],
    		Schema: []uint8 len: 4, cap: 43, [116,101,115,116],
    		Table: []uint8 len: 4, cap: 38, [98,111,111,107],
    		OrgTable: []uint8 len: 4, cap: 33, [98,111,111,107],
    		Name: []uint8 len: 7, cap: 28, [97,100,100,114,101,115,115],
    		OrgName: []uint8 len: 7, cap: 20, [97,100,100,114,101,115,115],
    		Charset: 33,
    		ColumnLength: 96,
    		Type: 253,
    		Flag: 0,
    		Decimal: 0,
    		DefaultValueLength: 0,
    		DefaultValue: []uint8 len: 0, cap: 0, nil,},
    	*{
    		Data: github.com/nooncall/shazam/mysql.FieldData len: 44, cap: 44, [3,100,101,102,4,116,101,115,116,4,98,111,111,107,4,98,111,111,107,5,112,104,111,110,101,5,112,104,111,110,101,12,33,0,96,0,0,0,253,0,0,0,0,0],
    		Schema: []uint8 len: 4, cap: 39, [116,101,115,116],
    		Table: []uint8 len: 4, cap: 34, [98,111,111,107],
    		OrgTable: []uint8 len: 4, cap: 29, [98,111,111,107],
    		Name: []uint8 len: 5, cap: 24, [112,104,111,110,101],
    		OrgName: []uint8 len: 5, cap: 18, [112,104,111,110,101],
    		Charset: 33,
    		ColumnLength: 96,
    		Type: 253,
    		Flag: 0,
    		Decimal: 0,
    		DefaultValueLength: 0,
    		DefaultValue: []uint8 len: 0, cap: 0, nil,},
    ]
    

    足够了

  • 相关阅读:
    JavaScript 将十进制数转换成格式类似于 0x000100 或 #000100 的十六进制数
    Java 从资源文件(.properties)中读取数据
    更改MySQL 5.7的数据库的存储位置
    PADS Layout VX.2.3 将PCB中的元器件封装保存到库
    怀疑安装MySQL之后,导致OrCAD Capture、Allegro就打不开
    Allegro PCB 转 PADS Layout 之后的修修补补
    Java 使用UDP传输一个小文本文件
    IntelliJ IDEA Commons IO环境搭建
    RestFul风格API(Swagger)--从零开始Swagger
    Spring容器的简单实现(IOC原理)
  • 原文地址:https://www.cnblogs.com/liuzhuan23/p/13323416.html
Copyright © 2011-2022 走看看