Hbase Solr 二级索引 同步int数据报错com.ngdata.hbaseindexer.parse.ByteArrayValueMappers: Error mapping byte

二级索引实现方式:Hbase + Key-Value Store Indexer + Solr

同步int数据时提示异常

异常如下

2019-12-16 17:39:18,346 WARN com.ngdata.hbaseindexer.parse.ByteArrayValueMappers: Error mapping byte value 101 to int
java.lang.IllegalArgumentException: offset (0) + length (4) exceed the capacity of the array: 3at org.apache.hadoop.hbase.util.Bytes.explainWrongLengthOrOffset(Bytes.java:838)at org.apache.hadoop.hbase.util.Bytes.toInt(Bytes.java:1004)at org.apache.hadoop.hbase.util.Bytes.toInt(Bytes.java:980)at com.ngdata.hbaseindexer.parse.ByteArrayValueMappers$1.mapInternal(ByteArrayValueMappers.java:37)at com.ngdata.hbaseindexer.parse.ByteArrayValueMappers$AbstractByteValueMapper.map(ByteArrayValueMappers.java:157)at com.ngdata.hbaseindexer.morphline.ExtractHBaseCellsBuilder$Mapping.extractWithSingleOutputField(ExtractHBaseCellsBuilder.java:204)at com.ngdata.hbaseindexer.morphline.ExtractHBaseCellsBuilder$Mapping.apply(ExtractHBaseCellsBuilder.java:197)at com.ngdata.hbaseindexer.morphline.ExtractHBaseCellsBuilder$ExtractHBaseCells.doProcess(ExtractHBaseCellsBuilder.java:83)at org.kitesdk.morphline.base.AbstractCommand.process(AbstractCommand.java:161)at org.kitesdk.morphline.base.AbstractCommand.doProcess(AbstractCommand.java:186)at org.kitesdk.morphline.base.AbstractCommand.process(AbstractCommand.java:161)at com.ngdata.hbaseindexer.morphline.LocalMorphlineResultToSolrMapper.map(LocalMorphlineResultToSolrMapper.java:230)at com.ngdata.hbaseindexer.morphline.MorphlineResultToSolrMapper.map(MorphlineResultToSolrMapper.java:145)at com.ngdata.hbaseindexer.indexer.Indexer$RowBasedIndexer.calculateIndexUpdates(Indexer.java:289)at com.ngdata.hbaseindexer.indexer.Indexer.indexRowData(Indexer.java:144)at com.ngdata.hbaseindexer.indexer.IndexingEventListener.processEvents(IndexingEventListener.java:98)at com.ngdata.sep.impl.SepEventExecutor$1.run(SepEventExecutor.java:97)at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:511)at java.util.concurrent.FutureTask.run(FutureTask.java:266)at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1149)at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624)at java.lang.Thread.run(Thread.java:748)

 服务调用的是Hbase jar包下的 Bytes.toInt方法,我们再idea中调用验证一下,提示异常和hbase-solr提示异常相同

int a = Bytes.toInt(Bytes.toBytes(111));
System.out.println(a);
System.out.println("-------------------");
int b = Bytes.toInt(Bytes.toBytes("101"));
System.out.println(b);输出如下:
111
-------------------
Exception in thread "main" java.lang.IllegalArgumentException: offset (0) + length (4) exceed the capacity of the array: 3at org.apache.hadoop.hbase.util.Bytes.explainWrongLengthOrOffset(Bytes.java:838)at org.apache.hadoop.hbase.util.Bytes.toInt(Bytes.java:1004)at org.apache.hadoop.hbase.util.Bytes.toInt(Bytes.java:980)at com.example.demo.Test.main(Test.java:23)

查看调用的方法 Bytes.toInt 中 , 我们发现方法会判断如果 offset + length > bytes.length 抛出异常,也就是我们传入数据的字节数小于 4 则会抛出 explainWrongLengthOrOffset 异常

 public static final int SIZEOF_INT = Integer.SIZE / Byte.SIZE; //SIZEOF_INT = 4/*** Converts a byte array to an int value* @param bytes byte array* @return the int value*/public static int toInt(byte[] bytes) {return toInt(bytes, 0, SIZEOF_INT);}public static int toInt(byte[] bytes, int offset, final int length) {if (length != SIZEOF_INT || offset + length > bytes.length) {throw explainWrongLengthOrOffset(bytes, offset, length, SIZEOF_INT);}if (UNSAFE_UNALIGNED) {return UnsafeAccess.toInt(bytes, offset);} else {int n = 0;for(int i = offset; i < (offset + length); i++) {n <<= 8;n ^= bytes[i] & 0xFF;}return n;}}private static IllegalArgumentExceptionexplainWrongLengthOrOffset(final byte[] bytes,final int offset,final int length,final int expectedLength) {String reason;if (length != expectedLength) {reason = "Wrong length: " + length + ", expected " + expectedLength;} else {reason = "offset (" + offset + ") + length (" + length + ") exceed the"+ " capacity of the array: " + bytes.length;}return new IllegalArgumentException(reason);}

 

 我们知道在java中 int 占用字节数为4 ,字符串"101"占用字节为3 ,所以当字符串小于 4 的时候,我们同步数据会报错

System.out.println("占用字节->"+"101".getBytes().length);输出如下:占用字节->3

这时可以猜想是不是传入字符串长度 >= 4 时候,就正常了

我们通过hbase put进去数据

put 'tableName','test1','fn:comments_count','1111'
put 'tableName','test2','fn:comments_count','11111'

我们发现日志中没有报错,并且solr中数据已经成功同步过去;但是发现同步过去的数据不对,并不是我们插入的

 

Cloudera 文档中提出可以实现 com.ngdata.hbaseindexer.parse.ByteArrayValueMapper 接口自定义类型

文档链接:https://docs.cloudera.com/documentation/enterprise/latest/topics/search_hbase_batch_indexer.html#id_dfb_g24_3db

 实现该接口,自定义类型解决上述问题

com.ngdata.hbaseindexer.parse.ByteArrayValueMapper 接口在jar包 hbase-indexer-engine-1.*-cdh*.*.*.jar 包中

该jar包可以从 /opt/cloudera/parcels/CDH-6.*.*-1.cdh6.*.*.p0.590678/lib/hbase-solr/lib 目录下找到,

> ls hbase-indexer-engine-1.*-cdh*.*.*.jar
hbase-indexer-engine-1.5-cdh6.0.1.jar

实现该接口

import com.google.common.collect.ImmutableList; 
import com.ngdata.hbaseindexer.parse.ByteArrayValueMapper;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.apache.hadoop.hbase.util.Bytes;import java.util.Collection;public class Jastint implements ByteArrayValueMapper {private static Log log = LogFactory.getLog(Jastint.class);public Collection<? extends Object> map(byte[] input) {try {return ImmutableList.of(mapInternal(Bytes.toString(input)));} catch (IllegalArgumentException e) {log.warn(String.format("Error mapping byte value %s to %s", Bytes.toStringBinary(input),int.class.getName()), e);return ImmutableList.of();}}private int mapInternal(String toString) {return Integer.parseInt(toString);}}

打成 jar 包,将jar传到 /opt/cloudera/parcels/CDH-6.*.*-1.cdh*.*.*.p0.590678/lib/hbase-solr/lib/ 目录下,Key-Value Store Indexer 服务启动时会读取该目录下的jar包

修改 Morphlines 配置文件如下,对 hbase_indexer_vt_fn_comments_count 字段 使用我们自定义的 com.jast.hbaseindexer.Jastint 类,注意这里要引用 包名+类名 否则会提示找不到类

SOLR_LOCATOR : {# Name of solr collectioncollection : hbaseindexer# ZooKeeper ensemblezkHost : "$ZK_HOST" 
}morphlines : [
{
id : WeiBoTableMap
importCommands : ["org.kitesdk.**", "com.ngdata.**"]commands : [                    {extractHBaseCells {mappings : [{inputColumn : "fn:name"outputField : "hbase_indexer_vt_fn_name" type : string source : value},{inputColumn : "fn:comments_count"outputField : "hbase_indexer_vt_fn_comments_count" type : "com.jast.hbaseindexer.Jastint"source : value},{inputColumn : "fn:text"outputField : "hbase_indexer_vt_fn_text" type : stringsource : value}]}}{ logDebug { format : "output record: {}", args : ["@{}"] } }
]
}
]

重启 Key-Value Store Indexer 服务,再次插入数据

put 'tableName','test1','fn:comments_count','2587'
put 'tableName','test2','fn:comments_count','2587'

插入成功 

 

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.mzph.cn/news/509838.shtml

如若内容造成侵权/违法违规/事实不符,请联系多彩编程网进行投诉反馈email:809451989@qq.com,一经查实,立即删除!

相关文章

jQuery设计动画

一、显隐效果show() show(duration,[callback])show([duration],[easing],[callback]) 参数说明&#xff1a;duration&#xff1a;为一个字符串或者数字&#xff0c;决定动画将运行多久callback&#xff1a;表示在动画完成时执行的函数。easing&#xff1a;为一个字符串&#x…

值得推荐的C/C++框架和库

下次造轮子前先看看现有的轮子吧 值得学习的C语言开源项目 - 1. Webbench Webbench是一个在linux下使用的非常简单的网站压测工具。它使用fork()模拟多个客户端同时访问我们设定的URL&#xff0c;测试网站在压力下工作的性能&#xff0c;最多可以模拟3万个并发连接去测试网站的…

CDH 6 安装 Hbase 二级索引 Solr + Key-Value Store Indexer

目录 一、集群安装Solr Key-Value Store Indexer 二、创建Hbase二级索引 1.更改表结构&#xff0c;允许复制 2.创建相应的SolrCloud集合 3.创建 collection实例并将配置文件上传到 zookeeper 4.创建 Lily HBase Indexer 配置 5.配置Morphline文件 6.注册 Lily HBase I…

glClipPlane剪裁平面

glClipPlane裁剪平面 (2012-02-21 12:49:18) 转载▼标签&#xff1a; 半平面 裁剪 线框 球体 表示 杂谈 分类&#xff1a; OPENGL void glClipPlane(GLenum plane, const GLdouble *equation); 定义一个裁剪平面。equation参数指向平面方程Ax By Cz D …

html思维导图

网页版&#xff1a;https://www.processon.com/view/link/5a658afae4b010a6e728e492

Hbase Solr 二级索引,更新数据部分字段丢失问题

问题&#xff1a; 第一次往hbase put数据&#xff0c;索引同步三个字段&#xff0c;第二次更新hbase数据&#xff0c;只更新一个字段&#xff0c;其他两个字段会消失。 原因&#xff1a; 在创建Hbase Indexer 时我们配置文件指定了 read-row"never" $ cat morphl…

c#事件和委托

一、委托(Delegate) 1、定义 delegate是C#中的一种类型&#xff0c;它实际上是一个能够持有对某个方法的引用的类。与其它的类不同&#xff0c;delegate类能够 拥有一个签名&#xff08;signature&#xff09;&#xff0c;并且它"只能持有与它的签名相匹配的方法的引用&qu…

Hbase二级索引 Solr 异常 The most likely cause is another Solr server (or another solr core in this server)

solr查询数据时候报错&#xff0c;去服务器查看该节点日志 {"responseHeader":{"status":503,"QTime":3,"params":{"q":"*:*","_":"1576753724528"}},"error":{"metadata&q…

MonoBehaviour常用方法

1.Start()在Update方法被调用之前开始调用Start方法&#xff0c;而且Start方法在整个MonoBehaviour生命周期内只被调用一次。Awake和Start不同的地方在于Start方法仅仅在脚本初始化后被调用&#xff0c;这样允许你延迟加载任何代码&#xff0c;直到代码真正被使用时。Awake方法…

Hbase RegionServer 启动失败 Time difference of xxx ms max allowed of 30000ms

Hbase RegionServer 启动报错 异常如下&#xff1a; STOPPED: Unhandled: org.apache.hadoop.hbase.ClockOutOfSyncException: Server hostname13,16020,1576647671625 has been rejected; Reported time is too far out of sync with master. Time difference of 32345ms …

unity3d UGUI视频教程

http://forum.china.unity3d.com/home.php?modspace&uid3418&dothread&viewme&typethread&orderdateline&fromspace&page1

CDH6.x Solr7.x 集成 Ik 分词

下载ik相关jar包&#xff1a; 链接&#xff1a;https://pan.baidu.com/s/19fydKWw15g8rPg4LW1cOtw 提取码&#xff1a;f2l8 在CDH安装目录下 查找CDH6 solr 的启动目录 [roothostname1 ~]# find /opt -name WEB-INF |grep solr /opt/cloudera/parcels/CDH-6.0.0-1.cdh6.0.0.p…

java Switch里面的类型问题

switch中可以为以下几种类型&#xff1a; byte、short、int注意没有longchar、string(jdk 1.7版本之后的 )枚举类型 Java 7之前&#xff0c;switch后面的括号里面只能放int类型的值&#xff0c;注意是只能放int类型&#xff0c;但是放byte&#xff0c;short&#xff0c;char类…

Unity3d常用插件

1,UI插件 - NGUI 3.9.2http://pan.baidu.com/s/1o6kst662,地图编辑器 - Tiled Map Editorhttp://www.mapeditor.org/download.html3,A*寻路插件 - A* Pathfinding Project Pro 3.7 最新版http://pan.baidu.com/s/1nty759n4,可视化脚本工具 - Playmaker 1.7.8 最新版http://pan.…

Solr 基础性能调优讲解

本篇文章我们来了解一下solr的性能方面的调优&#xff0c;分为Schema优化、索引更新与提交调优、索引合并性能调优、Solr缓存、Solr查询性能优化 Schema优化 1、indextrue比indexfalse在索引时占用更多的内存、索引合并和优化时间更长&#xff0c;索引体积也响应变的更大&…

C语言有参函数调用时参数值传递问题

http://blog.csdn.net/hehuimin6/article/details/38800459

Solr router 路由介绍

目录 1、compositeId路由 1.1、compositeId路由原理 1.2、compositeId路由查询 2、implicit路由 2.1、implicit路由原理 2.2、implicit路由查询 3、扩展 3.1、compositeId路由方式扩展 3.2、implicit路由方式扩张 solrcloud的官方文档有对路由的简短介绍&#xff0c;但…

行为树的原理及实现

查阅了一些行为树资料&#xff0c;目前最主要是参考了这篇文章&#xff0c;看完后感觉行为树实乃强大&#xff0c;绝对是替代状态机的不二之选。但从理论看起来很简单的行为树&#xff0c;真正着手起来却发现很多细节无从下手。 总结起来&#xff0c;就是&#xff1a; 1、行为树…

Unity 3D中的射线与碰撞检测

在我们的游戏开发过程中&#xff0c;有一个很重要的工作就是进行碰撞检测。例如在射击游戏中子弹是否击中敌人&#xff0c;在RPG游戏中是否捡到装备等等。在进行碰撞检测时&#xff0c;我们最常用的工具就是射线&#xff0c;Unity 3D的物理引擎也为我们提供了射线类以及相关的函…