首页 文章 精选 留言 我的

精选列表

搜索[Vite构建],共10000篇文章
优秀的个人博客,低调大师

Phoenix 构建二级索引

都来自官网,请看官网 http://phoenix.apache.org/secondary_indexing.html 下边分析全局索引和本地索引 Global Indexing 全局索引 Global indexing targets read heavy,low write uses cases. With global indexes, all the performance penalties for indexes occur at write time. We intercept the data table updates on write (DELETE, UPSERT VALUES and UPSERT SELECT), build the index update and then sent any necessary updates to all interested index tables. At read time, Phoenix will select the index table to use that will produce the fastest query time and directly scan it just like any other HBase table. By default, unless hinted, an index will not be used for a query that references a column that isn’t part of the index. Global indexing适用于多读少写的业务场景。使用Global indexing的话在写数据的时候会消耗大量开销,因为所有对数据表的更新操作(DELETE, UPSERT VALUES and UPSERT SELECT),会引起索引表的更新,而索引表是分布在不同的数据节点上的,跨节点的数据传输带来了较大的性能消耗。在读数据的时候Phoenix会选择索引表来降低查询消耗的时间。在默认情况下如果想查询的字段不是索引字段的话索引表不会被使用,也就是说不会带来查询速度的提升。 配置hbase-site.xml 使用Global Indexing的话需要配置hbase-site.xml,在HBase集群的每个regionserver节点的hbase-site.xml中加入如下配置并重启HBase集群。 <property> <name>hbase.regionserver.wal.codec</name> <value>org.apache.hadoop.hbase.regionserver.wal.IndexedWALEditCodec</value> </property> 如果是CDH版本,要通过该cloudera manager配置 hbase-配置 修改这里 测试索引 -- 注意phoenix最好全大写字母,这里码字方便,我全小写了,请注意 -- 创建表 create table company(id varchar primary key, name varchar, address varchar); --- 查看索引 !indexes company; -- 创建索引 create index my_index on company(name); --删除索引表 drop index my_index on company -- 查看表就会发现多了一张索引表 !tables SELET * FROM MY_INDEX 该表中会有2个字段,其中:ID是自动创建的,其实就是HBase中的主键RowKey,0:NAME是我们刚刚手动创建的。 -- 插入数据 upsert into company(id, name, address) values('001', 'dimensoft', 'nanjing'); -- 查询数据 select name,address from company where name='dimensoft'; -- 查询索引表MY_INDEX SELECT * FROM MY_INDEX 或者 scan 'MY_INDEX' 高能预警 > select name,address from company where name='dimensoft'; 这样的查询语句是不会用到索引表的 Global mutable index will not be used unless all of the columns referenced in the query are contained in the index. name字段虽然是索引字段但是address字段并不是索引字段!也就是说需要查询出来的字段必须都是索引字段如: > select name from company where name='dimensoft'; 如果希望使用索引表进行查询的话可以使用以下三种方式来解决这个问题: 强制使用索引表 在进行查询的时候通过sql语句强制使用索引查询。 > SELECT /*+ INDEX(company my_index) */ name,address FROM company WHERE name = 'dimensoft'; This will cause each data row to be retrieved when the index is traversed to find the missing address column value. This hint should only be used if you know that the index has good selective (i.e. a small number of table rows have a value of ‘dimensoft’ in this example), as otherwise you’ll get better performance by the default behavior of doing a full table scan. 这样的查询语句会导致二次检索数据表,第一次检索是去索引表中查找符合name为dimensoft的数据,这时候发现address字段并不在索引字段中,会去company表中第二次扫描,因此只有当用户明确知道符合检索条件的数据较少的时候才适合使用,否则会造成全表扫描,对性能影响较大。 创建covered index 创建索引的时候指定一个covered字段,先删除my_index索引 > drop index my_index on company; 创建covered index > create index my_index on company(name) include(address); This will cause the address column value to be copied into the index and kept in synch as it changes. This will obviously increase the size of the index. 使用这种方式创建的所有会导致address字段的值被拷贝到索引中,缺点就是会导致索引表大小有一定的增加。 查询索引表my_index数据。 > select * from my_index; 这里写图片描述 这里的数据是自动同步过来的,可以发现address字段的值也被存储了。 从HBase的CLI中查看MY_INDEX表数据会发现比不使用include的时候多了一行数值,并且里面包含了address字段的值。 > scan 'MY_INDEX' 这里写图片描述 这个时候就再使用下面的查询语句就会使用到索引来进行查询了。 > select name,address from company where name='dimensoft'; 使用Local Indexing创建索引 与Global Indexing不同,当使用Local Indexing的时候即使查询的所有字段都不在索引字段中时也会用到索引进行查询(这是由Local Indexing自动完成的)。这部分内容会放到后一篇文章详细介绍。 Local Indexing 本地索引 Local indexing targets write heavy, space constrained use cases. Just like with global indexes, Phoenix will automatically select whether or not to use a local index at query-time. With local indexes, index data and table data co-reside on same server preventing any network overhead during writes. Local indexes can be used even when the query isn’t fully covered (i.e. Phoenix automatically retrieve the columns not in the index through point gets against the data table). Unlike global indexes, all local indexes of a table are stored in a single, separate shared table.At read time when the local index is used, every region must be examined for the data as the exact region location of index data cannot be predetermined.Thus some overhead occurs at read-time. Local indexing适用于写操作频繁的场景。与Global indexing一样,Phoenix会自动判定在进行查询的时候是否使用索引。使用Local indexing时,索引数据和数据表的数据是存放在相同的服务器中的避免了在写操作的时候往不同服务器的索引表中写索引带来的额外开销。使用Local indexing的时候即使查询的字段不是索引字段索引表也会被使用,这会带来查询速度的提升,这点跟Global indexing不同。一个数据表的所有索引数据都存储在一个单一的独立的可共享的表中。在读取数据的时候,标红的那句话不会翻译大意就是在读数据的时候因为存储数据的region的位置无法预测导致性能有一定损耗。 配置hbase-site.xml 使用Local Indexing的话需要配置hbase-site.xml,在HBase集群的master节点的hbase-site.xml中添加如下配置并重启HBase集群。 Local indexing also requires special configurations in the master to ensure data table and local index regions co-location. 配置这个参数的目的是确保数据表与索引表协同定位。 <property> <name>hbase.master.loadbalancer.class</name> <value>org.apache.phoenix.hbase.index.balancer.IndexLoadBalancer</value> </property> <property> <name>hbase.coprocessor.master.classes</name> <value>org.apache.phoenix.hbase.index.master.IndexMasterObserver</value> </property> 高能预警:如果使用的是Phoenix 4.3+的版本的话 还需要在HBase集群的每个regionserver节点的 hbase-site.xml中添加如下配置并重启HBase集群。 To support local index regions merge on data regions merge you will need to add the following parameter to hbase-site.xml in all the region servers and restart. (It’s applicable for Phoenix 4.3+ versions) 这个配置是为了支持在数据region合并之上进行 索引region合并(这句话感觉翻译的不太准确)。 <property> <name>hbase.coprocessor.regionserver.classes</name> <value>org.apache.hadoop.hbase.regionserver.LocalIndexMerger</value> </property> 注意: 同理使用CDH版的要通过cloudera manager页面管理配置 测试二级索引 进入phoenix的CLI的界面创建company表。 > create table company(id varchar primary key, name varchar, address varchar); 这里写图片描述 查看company表索引 > !indexes company 这里写图片描述 2.3 创建索引 对company表的name字段创建索引,索引名为my_index。 > create local index my_index on company(name); 查看当前所有表会发现多一张MY_INDEX索引表,查询该表数据。 这里写图片描述 通过squirrel来查看company的索引字段。 这里写图片描述 从HBase的CLI界面查看当前所有表。 > list 这里写图片描述 高能预警:这里的索引表并不叫MY_INDEX,而是叫_LOCAL_IDX_COMPANY,但是在Phoenix的CLI中进行数据查询的时候仍然是使用MY_INDEX进行查询,应该是做了映射。 2.4 插入数据 在company表中添加测试数据。 > upsert into company(id, name, address) values('001', 'dimensoft', 'nanjing'); 2.5 查询数据 查看company表数据以及索引表my_index数据。 > select * from company; > select * from my_index; 这里写图片描述 从HBase的CLI界面查看索引表_LOCAL_IDX_COMPANY。 > scan '_LOCAL_IDX_COMPANY' 这里写图片描述 3个索引字段_INDEX_ID、NAME和ID的值被合并为索引表的rowKey,其中_INDEX_ID并没有值(\x000是十六进制表示,转换为字符串是空格)。 函数索引 Functional Indexes 函数索引从4.3版本就有,这种索引的内容不局限于列,还能在表达式上建立索引。如果你使用的表达式正好就是索引的话,数据也可以直接从这个索引获取,而不需要从数据库获取。比如说,在一个表达式上建立索引,这个表达式是UPPER(name) || '_test': <pre style="margin-top: 0px; margin-bottom: 0px; white-space: pre-wrap; word-wrap: break-word; box-sizing: border-box; font-family: "Courier New" !important; font-size: 12px !important;">CREATE INDEX index2_f ON hao1 (UPPER(name) || '_test');</pre> 同样的index2_f表会被建立,里面存储了表达式求值后的结果,和RowKey的关系。当然也可以添加INCLUDE作为覆盖索引,做了覆盖索引,就不需要再去原数据表中获取数据。但是数据会多很多。 image 在索引范围上,Phoenix的索引可以分为全局索引和本地索引,两种索引适合的场景不同。 创建异步索引 一般我们可以使用CREATE INDEX来创建一个索引,这是一种同步的方法。但是有时候我们创建索引的表非常大,我们需要等很长时间。Phoenix 4.5以后有一个异步创建索引的方式,使用关键字ASYNC来创建索引: CREATE INDEX index1_c ON hao1 (age) INCLUDE(name) ASYNC; 这时候创建的索引表中不会有数据。你还必须要单独的使用命令行工具来执行数据的创建。当语句给执行的时候,后端会启动一个map reduce任务,只有等到这个任务结束,数据都被生成在索引表中后,这个索引才能被使用。启动工具的方法: ${HBASE_HOME}/bin/hbase org.apache.phoenix.mapreduce.index.IndexTool --schema MY_SCHEMA --data-table MY_TABLE --index-table ASYNC_IDX --output-path ASYNC_IDX_HFILES 这个任务不会因为客户端给关闭而结束,是在后台运行。你可以在指定的文件ASYNC_IDX_HFILES中找到最终实行的结果。

优秀的个人博客,低调大师

用Docker构建LNMP环境(上)

利用docker搭建lnmp环境(上) 小知识: 1 2 3 docker镜像运行之后变成容器(dockerrun) Registry是Docker镜像的中央存储仓库(pull/push) https: //git.oschina.net/#从这个地方拉取git的仓库 1.源码克隆到自己的linux服务器上 1 2 3 4 5 6 7 8 [root@oldboy~]#gitclonehttps: //git.oschina.net/xxsl/docker-training.git InitializedemptyGitrepository in /root/docker-training/.git/ remote:Countingobjects:2045,done. remote:Compressingobjects:100%(1326/1326),done. remote:Total2045(delta681),reused2045(delta681) Receivingobjects:100%(2045/2045),7.22MiB|386KiB/s,done. Resolvingdeltas:100%(681/681),done. [root@oldboy~]# 2.创建centos7镜像其余的软件全部基于centos7 1 2 3 4 5 6 7 8 9 [root@oldboycentos7]#pwd /root/docker-training/centos7 [root@oldboycentos7]#dockerbuild-tcsphere/centos:7.1./ [root@oldboycentos7]#dockerimages REPOSITORYTAGIMAGEIDCREATEDVIRTUALSIZE csphere/centos7.1080063d1c72d6secondsago591.4MB jb/jobs03latestdd40474b2a4c17hoursago1.093MB jobs03latestdd40474b2a4c17hoursago1.093MB [root@oldboycentos7]# 3.解释说明Dockerfile 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 [root@oldboycentos7]#catDockerfile # #MAINTAINERCarson,C.J.Zeong<zcy@nicescale.com> #DOCKER-VERSION1.6.2 # #DockerizingCentOS7:DockerfileforbuildingCentOSimages # FROMcentos:centos7.1.1503 MAINTAINERCarson,C.J.Zeong<zcy@nicescale.com> ENVTZ "Asia/Shanghai" #ENV环境变量以后在docker容器run指令使用,并在容器运行保持 ENVTERMxterm ADDaliyun-mirror.repo/etc/yum.repos.d/CentOS-Base.repo ADDaliyun-epel.repo/etc/yum.repos.d/epel.repo RUNyuminstall-ycurlwgettarbzip2unzipvim-enhancedpasswdsudoyum-utilshostnamenet-toolsrsyncman&&\ yuminstall-ygccgcc-c++gitmakeautomakecmakepatchlogrotatepython-devellibpng-devellibjpeg-devel&&\ yuminstall-y--enablerepo=epelpwgenpython-pip&&\ yumcleanall RUNpipinstallsupervisor#RUN执行的指令 ADDsupervisord.conf/etc/supervisord.conf#将本地的文件上传至/etc/下命名为supervisord.conf RUNmkdir-p/etc/supervisor.conf.d&&\ mkdir-p/ var /log/supervisor EXPOSE22#告诉docker服务端容器暴露的端口 ENTRYPOINT[ "/usr/bin/supervisord" , "-n" , "-c" , "/etc/supervisord.conf" ] 4.docker使用一个镜像运行一个容器 1 2 3 4 dockerrun-d-p2222:22不管此个容器是否停止下次系统还是用2222来映射咱们dockefile中的22端口 dockerrun-d-P2222:22容器重启以后系统会随机的分配一个没有使用的端口 --name容器的名字 -d后台 5.创建centos7.1容器 1 2 3 [root@oldboy~]#dockerrun-d-p2222:22--name base csphere/centos:7.1#通过csphere/centos:7.1创建一个名字为 base 放在后台运行的docker容器 55e9793e58c0f70ec2d358d2eeb11e1a1afebe7987d64339da0a30da995ef340#容器的长id号返回来 [root@oldboy~]# 6.查看创建的容器 1 2 3 [root@oldboy~]#dockerps-a#查看容器 CONTAINERIDIMAGECOMMANDCREATEDSTATUSPORTSNAMES 55e9793e58c0csphere/centos:7.1"/usr/bin/supervisor2minutesagoUp2minutes0.0.0.0:2222->22/tcp base 7.创建php的容器(以及运行php的容器) 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 [root@oldboyphp-fpm]#dockerbuild-tcsphere/php-fpm:5.4. 最后的内容 Removingintermediatecontainera3b57f2eb456 Successfullybuilt38d1572aef94 [root@oldboyphp-fpm]#dockerimages REPOSITORYTAGIMAGEIDCREATEDVIRTUALSIZE csphere/php-fpm5.438d1572aef9436secondsago685MB csphere/centos7.1080063d1c72d49minutesago591.4MB [root@oldboyphp-fpm]#dockerrun-d-p8080:80--namewebsitecsphere/php-fpm:5.4 [root@oldboyphp-fpm]#dockerps-a CONTAINERIDIMAGECOMMANDCREATEDSTATUSPORTSNAMES cf1f2bd73808csphere/php-fpm:5.4"/usr/bin/supervisor8secondsagoUp8seconds22/tcp,443/tcp,0.0.0.0:8080->80/tcpwebsite 55e9793e58c0csphere/centos:7.1"/usr/bin/supervisor33minutesagoUp33minutes0.0.0.0:2222->22/tcp base 测试容器OK 8进入一个docker内部查看 1 2 3 4 5 6 7 8 9 [root@oldboyphp-fpm]#dockerexec-itwebsite/bin/bash [root@cf1f2bd73808/]#supervisor supervisorctlsupervisord [root@cf1f2bd73808/]#supervisor supervisorctlsupervisord [root@cf1f2bd73808/]#supervisorctl nginxRUNNINGpid10,uptime0:07:30 php-fpmRUNNINGpid11,uptime0:07:30 supervisor>exit 9.创建mysql的容器 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 [root@oldboymysql]#dockerbuild-tcsphere/mysql:5.5./ [root@oldboymysql]#dockerimages REPOSITORYTAGIMAGEIDCREATEDVIRTUALSIZE csphere/mysql5.563b2bd2cab9735secondsago725.1MB csphere/php-fpm5.438d1572aef9433minutesago685MB csphere/centos7.1080063d1c72dAboutanhourago591.4MB [root@oldboymysql]#dockerrun-d-p3305:3306--namedbservercsphere/mysql:5.5 36fb44b10702ad1eb38f646e381354ef8b2d832d27b54f8eb3ce5424b6c41e7e [root@oldboymysql]#dockerps-a CONTAINERIDIMAGECOMMANDCREATEDSTATUSPORTSNAMES 36fb44b10702csphere/mysql:5.5 "/scripts/start" 9secondsagoUp8seconds22/tcp,0.0.0.0:3305->3306/tcpdbserver cf1f2bd73808csphere/php-fpm:5.4"/usr/bin/supervisor27minutesagoUp27minutes22/tcp,443/tcp,0.0.0.0:8080->80/tcpwebsite 55e9793e58c0csphere/centos:7.1"/usr/bin/supervisorAboutanhouragoUpAboutanhour0.0.0.0:2222->22/tcp base 进入docker容器内部 [root@oldboy~]#dockerexec-itdbserver/bin/bash#进入容器的命令 10-v参数的使用 可以挂载一个目录到本地,docker投容器mysql这个容器如果被删除了那么还可以恢复数据数据文件还在的 此处的思想就是:先用-v 参数启动一个数据库的docker容器,然后删除容器,再次新建一个数据库的docker容器,,挂载的目录还是原来的目录可以看出数据依然还在 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 dockerrun-d-p3306:3306-v/ var /lib/docker/vfs/dir/mydata:/ var /lib/mysqlcsphere/mysql:5.5 dockerexec-ite5387295506f/bin/bash mysql showdatabases; createdatabasemydb; [root@oldboycentos7]#cd/ var /lib/docker/vfs/dir/mydata/ [root@oldboymydata]#ls aria_log.00000001ibdata1ib_logfile1mysqlperformance_schema aria_log_controlib_logfile0mydbmysql.socktest [root@oldboymydata]# 准备删除docker容器 [root@oldboymydata]#dockerps-a CONTAINERIDIMAGECOMMANDCREATEDSTATUSPORTSNAMES e5387295506fcsphere/mysql:5.5 "/scripts/start" 36minutesagoUp36minutes22/tcp,0.0.0.0:3306->3306/tcpsuspicious_morse [root@oldboymydata]#dockerrm-fe5387295506f#强制删除一个容器也可以dockerstope5387295506f&&dockerrme5387295506f e5387295506f [root@oldboymydata]#cd/ var /lib/docker/vfs/dir/mydata/#可以看出容器被删除了但是数据还在 [root@oldboymydata]#ls aria_log.00000001ibdata1ib_logfile1mysqlperformance_schema aria_log_controlib_logfile0mydbmysql.socktest [root@oldboymydata]# [root@oldboymydata]#dockerrun-d-p3306:3306--namenewdb-v/ var /lib/docker/vfs/dir/mydata:/ var /lib/mysqlcsphere/mysql:5.5#生成新的数据进行再次挂载 d9dddf959cdfdf7506812b8da258e8ac74e3af5cdf3223bbc26b24fcb2289fee [root@oldboymydata]# [root@oldboymydata]#dockerexec-itnewdb/bin/bash#再次进入 [root@d9dddf959cdf/]#mysql showdatabases;#可以看出以前创建的数据库还在 本文转自 小小三郎1 51CTO博客,原文链接:http://blog.51cto.com/wsxxsl/1834558,如需转载请自行联系原作者

资源下载

更多资源
优质分享App

优质分享App

近一个月的开发和优化,本站点的第一个app全新上线。该app采用极致压缩,本体才4.36MB。系统里面做了大量数据访问、缓存优化。方便用户在手机上查看文章。后续会推出HarmonyOS的适配版本。

Nacos

Nacos

Nacos /nɑ:kəʊs/ 是 Dynamic Naming and Configuration Service 的首字母简称,一个易于构建 AI Agent 应用的动态服务发现、配置管理和AI智能体管理平台。Nacos 致力于帮助您发现、配置和管理微服务及AI智能体应用。Nacos 提供了一组简单易用的特性集,帮助您快速实现动态服务发现、服务配置、服务元数据、流量管理。Nacos 帮助您更敏捷和容易地构建、交付和管理微服务平台。

Rocky Linux

Rocky Linux

Rocky Linux(中文名:洛基)是由Gregory Kurtzer于2020年12月发起的企业级Linux发行版,作为CentOS稳定版停止维护后与RHEL(Red Hat Enterprise Linux)完全兼容的开源替代方案,由社区拥有并管理,支持x86_64、aarch64等架构。其通过重新编译RHEL源代码提供长期稳定性,采用模块化包装和SELinux安全架构,默认包含GNOME桌面环境及XFS文件系统,支持十年生命周期更新。

Sublime Text

Sublime Text

Sublime Text具有漂亮的用户界面和强大的功能,例如代码缩略图,Python的插件,代码段等。还可自定义键绑定,菜单和工具栏。Sublime Text 的主要功能包括:拼写检查,书签,完整的 Python API , Goto 功能,即时项目切换,多选择,多窗口等等。Sublime Text 是一个跨平台的编辑器,同时支持Windows、Linux、Mac OS X等操作系统。

用户登录
用户注册
修改密码
忘记密码