首页 文章 精选 留言 我的

精选列表

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

openstack之nova启动实例过程

概述: 启动一个实例包含以下步骤: API server:处理用户请求并转发至cloud controller cloud controller:处理计算节点、网络控制、api server 以及scheduler的通信 scheduler:选择节点启动实例 Compute worker:管理实例,启动/关闭实例,挂载/卸载卷 Network controller:管理网络资源,分配浮动ip、配置vlan 启动实例的流程类似于这样: API服务从用户收到一个run_instances的命令,API服务转发这个命令给云控制器(1),在这里执行认证以确保该用户有相应的权限.去控制器把这条信息发给调度(2). 调度将这条信息扔给一个随机的主机(计算节点)让他启动一个新的实例(3).这台主机上的计算服务抓到这条信息(4).计算服务需要一个fixed IP来启动一个新实例,所以她发了一条信息给网络控制器(5,6,7,8).计算服务继续创建这个实例.下面我们将深入这些步骤的细节中去

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

HBase源码分析之Region定位

我们知道,HBase是一个基于RowKey进行检索的分布式数据库。它按照行的方向将表中的数据切分成一个个Region,而每个Region都会存在一个起始行StartKey和一个终止行EndKey。Region会最终选择一个RegionSever上线,并依靠RegionSever对外提供数据存取服务。那么,HBase是如何实现数据的检索,也就是它如何将需要读写的行Row准确的定位到其所在Region和RegionServer上的呢?本文,我们就将研究下HRegion的定位。 之前我们已经研究过HBase读取数据的应用--Scan,在Scan的过程中,它每次通过RPC与服务端通信,都是针对特定的Region及其所在RegionServer进行数据读取请求,将数据缓存至客户端。在它迭代获取数据的Scanner的next()中,会检查缓存中是否存在数据,若无,则加载缓存,然后直接从缓存中拉取数据,代码如下: @Override public Result next() throws IOException { // If the scanner is closed and there's nothing left in the cache, next is a no-op. if (cache.size() == 0 && this.closed) { return null; } // 如果缓存中不存在数据,调用loadCache()方法加载缓存 if (cache.size() == 0) { loadCache(); } // 缓存中存在数据的话,直接从缓存中拉取数据,返回给客户端请求者 if (cache.size() > 0) { return cache.poll(); } // if we exhausted this scanner before calling close, write out the scan metrics writeScanMetrics(); return null; } 而这个加载缓存的loadCache()方法,则会调用call()方法,发送RPC请求给对应的RegionServer上的Region,那么它是如何定位Region的呢?我们先看下这个call()方法,代码如下: Result[] call(Scan scan, ScannerCallableWithReplicas callable, RpcRetryingCaller<Result[]> caller, int scannerTimeout) throws IOException, RuntimeException { if (Thread.interrupted()) { throw new InterruptedIOException(); } // callWithoutRetries is at this layer. Within the ScannerCallableWithReplicas, // we do a callWithRetries // caller为RpcRetryingCaller类型 // callable为ScannerCallableWithReplicas类型 return caller.callWithoutRetries(callable, scannerTimeout); } 实际上caller为RpcRetryingCaller类型,而callable为ScannerCallableWithReplicas类型,我们看下RpcRetryingCaller的callWithoutRetries()方法,关键代码如下: // 先调用prepare()方法,再调用call()方法,超时时间为callTimeout callable.prepare(false); return callable.call(callTimeout); 发现没,实际上最终调用的是callable的call()方法,也就是ScannerCallableWithReplicas的call()方法,我们跟进下关键代码: @Override public Result [] call(int timeout) throws IOException { // 此处省略代码若干字...... // 根据scan的startRow获取Region位置,使用cache RegionLocations rl = RpcRetryingCallerWithReadReplicas.getRegionLocations(true, RegionReplicaUtil.DEFAULT_REPLICA_ID, cConnection, tableName, currentScannerCallable.getRow()); // 此处省略代码若干字...... } 终于切入主题了!Region的定位是通过调用RpcRetryingCallerWithReadReplicas的getRegionLocations()方法进行的,它需要是否使用缓存标识位useCache、主从复制replicaId、ClusterConnection集群连接器cConnection,表名tableName、所在行Row等关键参数,并返回RegionLocations,用于表示Region的位置信息。而RegionLocations中存在一个数组locations,它的定义如下: // locations array contains the HRL objects for known region replicas indexes by the replicaId. // elements can be null if the region replica is not known at all. A null value indicates // that there is a region replica with the index as replicaId, but the location is not known // in the cache. private final HRegionLocation[] locations; // replicaId -> HRegionLocation. 它是一个HRegionLocation类型的数组,实际上存储的是replicaId到HRegionLocation的映射,replicaId就是数组的下标。而上面调用getRegionLocations()方法时,传入的replicaId为RegionReplicaUtil.DEFAULT_REPLICA_ID,也就是0。那么HRegionLocation是什么呢?看下它的两个关键成员变量就知道了: private final HRegionInfo regionInfo; private final ServerName serverName; HRegionLocation就是Region的位置信息,它包含了关键的两点信息:1、数据读写请求中row所在Region信息HRegionInfo;2、Region所在服务器ServerName。有了这两点,我们就能够掌握row对应Region位置信息了。 言归正传,我们从RpcRetryingCallerWithReadReplicas的getRegionLocations()方法开始,代码如下: static RegionLocations getRegionLocations(boolean useCache, int replicaId, ClusterConnection cConnection, TableName tableName, byte[] row) throws RetriesExhaustedException, DoNotRetryIOException, InterruptedIOException { RegionLocations rl; try { // 根据表名tableName,行row,和副本replicaId,来定位Region位置,得到RegionLocations,即rl if (!useCache) { // 不使用缓存,调用ClusterConnection的relocateRegion()方法,定位Region位置 rl = cConnection.relocateRegion(tableName, row, replicaId); } else { // 使用缓存,调用ClusterConnection的locateRegion()方法,定位Region位置 rl = cConnection.locateRegion(tableName, row, useCache, true, replicaId); } } catch (DoNotRetryIOException e) { throw e; } catch (RetriesExhaustedException e) { throw e; } catch (InterruptedIOException e) { throw e; } catch (IOException e) { throw new RetriesExhaustedException("Can't get the location", e); } if (rl == null) { throw new RetriesExhaustedException("Can't get the locations"); } return rl; } 其实逻辑很简单,就分两种情况,使用缓存和不使用缓存。而且,我们也应该能猜出来,即便是使用缓存,如果缓存中没有的话,它还是会走一遍不使用缓存的流程,将获取到的Region位置信息加载到缓存中,然后再返回给外部调用者,最终我们需要共同研究的仅仅是不使用缓存的情况下如何定位Region而已。到底是不是这样呢?我们先记住,后面再做验证。 首先,我们来看下不使用缓存的情况下,是如何进行Region定位的。它调用的是ClusterConnection的relocateRegion()方法,而这个ClusterConnection是一个接口,它的实例化,是在HTable中进行,然后一层层传递过来的。我们先看下它的实例化,在HTable的构造方法中,代码如下: this.connection = ConnectionManager.getConnectionInternal(conf); 通过ConnectionManager的静态方法getConnectionInternal(),从配置信息conf中加载而来。继续看下它的代码: static ClusterConnection getConnectionInternal(final Configuration conf) throws IOException { // 根据配置信息conf构造HConnectionKey HConnectionKey connectionKey = new HConnectionKey(conf); synchronized (CONNECTION_INSTANCES) { // 先从CONNECTION_INSTANCES中根据HConnectionKey获取连接HConnectionImplementation类型的connection, // CONNECTION_INSTANCES为HConnectionKey到HConnectionImplementation的映射集合 HConnectionImplementation connection = CONNECTION_INSTANCES.get(connectionKey); if (connection == null) {// 如果CONNECTION_INSTANCES中不存在 // 调用createConnection()方法创建一个HConnectionImplementation connection = (HConnectionImplementation)createConnection(conf, true); // 将新创建的HConnectionImplementation与HConnectionKey的对应关系存入CONNECTION_INSTANCES CONNECTION_INSTANCES.put(connectionKey, connection); } else if (connection.isClosed()) {// 如果CONNECTION_INSTANCES中存在,且已关闭的话 // 调用ConnectionManager的deleteConnection()方法,删除connectionKey对应的记录: // 1、调用decCount()方法减少计数; // 2、从CONNECTION_INSTANCES类表中移除connectionKey对应记录; // 3、调用HConnectionImplementation的internalClose()方法处理关闭连接事宜 ConnectionManager.deleteConnection(connectionKey, true); // 调用createConnection()方法创建一个HConnectionImplementation connection = (HConnectionImplementation)createConnection(conf, true); // 将新创建的HConnectionImplementation与HConnectionKey的对应关系存入CONNECTION_INSTANCES CONNECTION_INSTANCES.put(connectionKey, connection); } // 连接计数器增1 connection.incCount(); // 返回连接 return connection; } } 这个HConnectionKey实际上是连接的一个Key类,包含了连接对应的hbase.zookeeper.quorum、hbase.zookeeper.property.clientPort等重要信息,而获取连接的方法也很简单,如果之前创建过key相同的连接,直接从CONNECTION_INSTANCES集合中根据HConnectionKey获取,并将连接计数器增1,直接返回连接,获取不到的话,根据HConnectionKey创建一个新的,并加入CONNECTION_INSTANCES集合,而且,如果获取到的连接是Closed的话,调用ConnectionManager的deleteConnection()方法,删除connectionKey对应的记录,创建一个新的连接创建一个HConnectionImplementation,并加入到CONNECTION_INSTANCES集合。 我们已经知道,上述ClusterConnection的实现类就是HConnectionImplementation,那么我们回到正轨上,继续研究Region的定位,先看下不使用缓存的情况的情况下是如何处理的。好,我们进入HConnectionImplementation的relocateRegion()方法,代码如下: @Override public RegionLocations relocateRegion(final TableName tableName, final byte [] row, int replicaId) throws IOException{ // Since this is an explicit request not to use any caching, finding // disabled tables should not be desirable. This will ensure that an exception is thrown when // the first time a disabled table is interacted with. // 既然这是一个明确不使用任何缓存的请求,如果发现表被禁用,那么这将是不可取的。 // 当我们第一时间发现表被禁用时,这里将会确保一个异常被抛出。 // 如果表不是META表,并且表被禁用的话,直接抛出TableNotEnabledException if (!tableName.equals(TableName.META_TABLE_NAME) && isTableDisabled(tableName)) { throw new TableNotEnabledException(tableName.getNameAsString() + " is disabled."); } // 调用locateRegion方法进行Region的定位,传入的useCache为false,retry为true,即不使用缓存,并且进行重试 return locateRegion(tableName, row, false, true, replicaId); } 很简单,先做一个必要的检查,如果表不是META表,并且表被禁用的话,直接抛出TableNotEnabledException,然后调用locateRegion()方法进行Region的定位,传入的useCache为false,retry为true,即不使用缓存,并且进行重试。 在分析locateRegion()方法前,我们先折回去看看使用缓存情况的处理,它也是调用的locateRegion()方法,只不过传入的使用缓存标志位useCache为true这一个区别而已,好了,殊途同归,这里我们就只研究locateRegion()方法就行了,代码如下: @Override public RegionLocations locateRegion(final TableName tableName, final byte [] row, boolean useCache, boolean retry, int replicaId) throws IOException { // 判断连接是否已关闭的标志位closed,为true则直接抛出IOException异常 if (this.closed) throw new IOException(toString() + " closed"); // 判断表名tableName,表名为空的话直接抛出IllegalArgumentException异常 if (tableName== null || tableName.getName().length == 0) { throw new IllegalArgumentException( "table name cannot be null or zero length"); } if (tableName.equals(TableName.META_TABLE_NAME)) { // 如果是meta表,直接调用locateMeta()方法进行定位 return locateMeta(tableName, useCache, replicaId); } else { // Region not in the cache - have to go to the meta RS // 如果不是meta表,cache中没有,需要访问meta RS,调用locateRegionInMeta()方法进行定位 return locateRegionInMeta(tableName, row, useCache, retry, replicaId); } } locateRegion()方法上来先做一些必要的检查: 1、判断连接是否已关闭的标志位closed,为true则直接抛出IOException异常; 2、判断表名tableName,表名为空的话直接抛出IllegalArgumentException异常。 然后,根据表是否为meta表,做以下处理: 1、如果是meta表,直接调用locateMeta()方法进行定位; 2、如果不是meta表,cache中没有,需要访问meta RS,调用locateRegionInMeta()方法进行定位; 我们今天先看非meta表,进入locateRegionInMeta()方法,代码如下: /* * Search the hbase:meta table for the HRegionLocation * info that contains the table and row we're seeking. * * 搜索HBase的meta表,找出包含我们正在查找的table及row相关的HRegionLocation信息 */ private RegionLocations locateRegionInMeta(TableName tableName, byte[] row, boolean useCache, boolean retry, int replicaId) throws IOException { // If we are supposed to be using the cache, look in the cache to see if // we already have the region. // 如果我们支持在缓存中查找,先在缓存中看看是否我们已经有该Region if (useCache) { RegionLocations locations = getCachedLocation(tableName, row); if (locations != null && locations.getRegionLocation(replicaId) != null) { return locations; } } // build the key of the meta region we should be looking for. // the extra 9's on the end are necessary to allow "exact" matches // without knowing the precise region names. // 缓存中没有,构造一个scan // 根据表名tableName、行row、字符串"99999999999999",调用HRegionInfo的createRegionName()方法, // 创建一个Region Name:metaKey byte[] metaKey = HRegionInfo.createRegionName(tableName, row, HConstants.NINES, false); // 构造一个Scan,scan的起始行为上述metaKey,并且是一个反向小scan,即reversed small Scan Scan s = new Scan(); s.setReversed(true); s.setStartRow(metaKey); s.setSmall(true); s.setCaching(1); // 确定重试次数 int localNumRetries = (retry ? numTries : 1); for (int tries = 0; true; tries++) { // 重试次数超过上限的话,直接抛出NoServerForRegionException异常, // 重试次数上限取参数hbase.client.retries.number,参数未配置的话默认为31 if (tries >= localNumRetries) { throw new NoServerForRegionException("Unable to find region for " + Bytes.toStringBinary(row) + " in " + tableName + " after " + localNumRetries + " tries."); } if (useCache) {// 如果支持使用缓存的话 // 每次再从缓存中取一遍 RegionLocations locations = getCachedLocation(tableName, row); if (locations != null && locations.getRegionLocation(replicaId) != null) { return locations; } } else { // If we are not supposed to be using the cache, delete any existing cached location // so it won't interfere. // 如果我们不支持使用缓存,删除任何存在的相关缓存,以确保它不会干扰我们的查询 // 调用metaCache的clearCache()方法,根据tableName和row来删除 metaCache.clearCache(tableName, row); } // Query the meta region try { Result regionInfoRow = null; ReversedClientScanner rcs = null; try { // 构造ClientSmallReversedScanner实例rcs,从meta表中查找, // 而meta表的表名固定为hbase:meta,它的namespace为"meta",qualifier为"meta" rcs = new ClientSmallReversedScanner(conf, s, TableName.META_TABLE_NAME, this, rpcCallerFactory, rpcControllerFactory, getBatchPool(), 0); // 通过scanner的next()方法,获取唯一的结果regionInfoRow regionInfoRow = rcs.next(); } finally { // 关闭ClientSmallReversedScanner if (rcs != null) { rcs.close(); } } if (regionInfoRow == null) {// 如果regionInfoRow为空,直接抛出TableNotFoundException异常 throw new TableNotFoundException(tableName); } // convert the row result into the HRegionLocation we need! // 将Result转换为我们需要的RegionLocations,即regionInfoRow->locations RegionLocations locations = MetaTableAccessor.getRegionLocations(regionInfoRow); if (locations == null || locations.getRegionLocation(replicaId) == null) { throw new IOException("HRegionInfo was null in " + tableName + ", row=" + regionInfoRow); } // 从locations中获取Region信息HRegionInfo HRegionInfo regionInfo = locations.getRegionLocation(replicaId).getRegionInfo(); if (regionInfo == null) { throw new IOException("HRegionInfo was null or empty in " + TableName.META_TABLE_NAME + ", row=" + regionInfoRow); } // possible we got a region of a different table... // 验证表名是否一致 if (!regionInfo.getTable().equals(tableName)) { throw new TableNotFoundException( "Table '" + tableName + "' was not found, got: " + regionInfo.getTable() + "."); } // 验证Rgion是否已分裂 if (regionInfo.isSplit()) { throw new RegionOfflineException("the only available region for" + " the required row is a split parent," + " the daughters should be online soon: " + regionInfo.getRegionNameAsString()); } // 验证Rgion是否已下线 if (regionInfo.isOffline()) { throw new RegionOfflineException("the region is offline, could" + " be caused by a disable table call: " + regionInfo.getRegionNameAsString()); } // 从locations中根据replicaId获取ServerName ServerName serverName = locations.getRegionLocation(replicaId).getServerName(); if (serverName == null) { throw new NoServerForRegionException("No server address listed " + "in " + TableName.META_TABLE_NAME + " for region " + regionInfo.getRegionNameAsString() + " containing row " + Bytes.toStringBinary(row)); } // 验证ServerName是否已死亡 if (isDeadServer(serverName)){ throw new RegionServerStoppedException("hbase:meta says the region "+ regionInfo.getRegionNameAsString()+" is managed by the server " + serverName + ", but it is dead."); } // Instantiate the location // 缓存获得的位置信息 cacheLocation(tableName, locations); return locations; } catch (TableNotFoundException e) { // if we got this error, probably means the table just plain doesn't // exist. rethrow the error immediately. this should always be coming // from the HTable constructor. throw e; } catch (IOException e) { ExceptionUtil.rethrowIfInterrupt(e); if (e instanceof RemoteException) { e = ((RemoteException)e).unwrapRemoteException(); } if (tries < localNumRetries - 1) { if (LOG.isDebugEnabled()) { LOG.debug("locateRegionInMeta parentTable=" + TableName.META_TABLE_NAME + ", metaLocation=" + ", attempt=" + tries + " of " + localNumRetries + " failed; retrying after sleep of " + ConnectionUtils.getPauseTime(this.pause, tries) + " because: " + e.getMessage()); } } else { throw e; } // Only relocate the parent region if necessary if(!(e instanceof RegionOfflineException || e instanceof NoServerForRegionException)) { relocateRegion(TableName.META_TABLE_NAME, metaKey, replicaId); } } try{ // 当前线程休眠一段时间,再次重试,休眠的时间与pause和tries有关,越往后,停顿时间一般越长(波动时间除外) Thread.sleep(ConnectionUtils.getPauseTime(this.pause, tries)); } catch (InterruptedException e) { throw new InterruptedIOException("Giving up trying to location region in " + "meta: thread is interrupted."); } } } locateRegionInMeta()方法是对非Meta表中特定行row所在Region位置信息的检索,它本质上是通过检索HBase中Meta表数据来获取对应非Meta表中行row对应的Region位置信息的,其处理逻辑如下: 1、根据标志位useCache确定:如果我们支持在缓存中查找,先在缓存中看看是否我们已经有该Region,调用的是getCachedLocation()方法,传入tableName和row即可,存在即返回,否则继续; 2、缓存中没有,构造一个scan,先根据表名tableName、行row、字符串"99999999999999",调用HRegionInfo的createRegionName()方法,创建一个Region Name:metaKey; 3、构造一个Scan,scan的起始行为上述metaKey,并且是一个反向小scan,即reversed small Scan; 4、确定重试上限次数localNumRetries:如果标志位retry为true的话,重试上限次数localNumRetries取numTries,即取参数hbase.client.retries.number,参数未配置的话默认为31; 5、在一个循环内,当重试次数tries未达到上限localNumRetries且未定位到对应Region位置信息时: 5.1、先判断重试次数tries是否达到上限localNumRetries,达到的话,直接抛出NoServerForRegionException异常; 5.2、根据是否支持从缓存中取来判断: 5.2.1、如果支持使用缓存的话,每次再从缓存中取一遍,存在即返回,否则继续; 5.2.2、如果我们不支持使用缓存,删除任何存在的相关缓存,以确保它不会干扰我们的查询,调用metaCache的clearCache()方法,根据tableName和row来删除; 5.3、构造ClientSmallReversedScanner实例rcs,从meta表中查找,而meta表的表名固定为hbase:meta,它的namespace为"meta",qualifier为"meta",获取scanner,注意,这一步实际上是一个内嵌的scan,它也需要根据表和行进行Region的定位,而这个表就是HBase中的Meta表,既然从Meta表中查找数据,那么就又折回到上面针对Meta表和非Meta标的的if...else...判断了,关于Meta表的定位我们稍等再讲; 5.4、通过scanner的next()方法,获取唯一的结果regionInfoRow; 5.5、关闭ClientSmallReversedScanner; 5.6、如果regionInfoRow为空,直接抛出TableNotFoundException异常; 5.7、将Result转换为我们需要的RegionLocations,即regionInfoRow->locations; 5.8、从locations中获取Region信息HRegionInfo; 5.9、做一些必要的数据和状态校验,比如: 5.9.1、验证表名是否一致; 5.9.2、验证Rgion是否已分裂; 5.9.3、验证Rgion是否已下线; 5.9.4、从locations中根据replicaId获取ServerName,验证ServerName是否已死亡; 5.10、调用cacheLocation()方法缓存获得的位置信息locations,并返回; 5.11、如果中间出现异常,则当前线程休眠一段时间,再次重试,休眠的时间与pause和tries有关,越往后,停顿时间一般越长(波动时间除外)。 整个过程就是如此。接下来,我们针对其中的几点,做一些细节方面的介绍。 一、从缓存中看看是否我们已经有该Region的getCachedLocation()方法 首先我们看下从缓存中看看是否我们已经有该Region的getCachedLocation()方法,代码如下: /** * Search the cache for a location that fits our table and row key. * Return null if no suitable region is located. * * @param tableName * @param row * @return Null or region location found in cache. */ RegionLocations getCachedLocation(final TableName tableName, final byte [] row) { return metaCache.getCachedLocation(tableName, row); } 它实际上是从metaCache中获取tableName和row所对应的Region位置信息。而metaCache是一个叫做MetaCache类的对象,它是为缓存Region位置信息,即Meta Data而专门设计的一个数据结构,我们先看下它的getCachedLocation()方法: /** * Search the cache for a location that fits our table and row key. * Return null if no suitable region is located. * * * @param tableName * @param row * @return Null or region location found in cache. */ public RegionLocations getCachedLocation(final TableName tableName, final byte [] row) { // 首先根据tableName获取缓存的该表相关的位置信息tableLocations,它是一个保存的row到RegionLocations映射的跳表结构ConcurrentSkipListMap ConcurrentSkipListMap<byte[], RegionLocations> tableLocations = getTableLocations(tableName); // 从tableLocations中根据row获取到小于或等于row的最大row到RegionLocations映射的条目 Entry<byte[], RegionLocations> e = tableLocations.floorEntry(row); if (e == null) { // 查询不到的话直接返回 return null; } // 获取Region的位置信息possibleRegion RegionLocations possibleRegion = e.getValue(); // make sure that the end key is greater than the row we're looking // for, otherwise the row actually belongs in the next region, not // this one. the exception case is when the endkey is // HConstants.EMPTY_END_ROW, signifying that the region we're // checking is actually the last region in the table. // 从possibleRegion中获取Rgion对应的endKey byte[] endKey = possibleRegion.getRegionLocation().getRegionInfo().getEndKey(); // 如果endKey为byte [0],或者row大于endKey,恭喜,找到啦!!那么我们就返回这个possibleRegion if (Bytes.equals(endKey, HConstants.EMPTY_END_ROW) || tableName.getRowComparator().compareRows( endKey, 0, endKey.length, row, 0, row.length) > 0) { return possibleRegion; } // Passed all the way through, so we got nothing - complete cache miss // 最后,没办法,没有找到,返回null吧 return null; } 逻辑比较简单,注释也很清晰,读者可自行分析。这里要着重说下ConcurrentSkipListMap,它提供了一种线程安全的并发访问的排序映射表。内部是SkipList(跳表)结构实现,在理论上能够在O(log(n))时间内完成查找、插入、删除操作。读者可自行查阅ConcurrentSkipListMap的相关介绍。而根据tableName获取缓存的该表相关的位置信息tableLocations的getTableLocations()方法,如下: /** * @param tableName * @return Map of cached locations for passed <code>tableName</code> */ private ConcurrentSkipListMap<byte[], RegionLocations> getTableLocations(final TableName tableName) { // find the map of cached locations for this table ConcurrentSkipListMap<byte[], RegionLocations> result; // 从cachedRegionLocations中根据tableName获取缓存的该表相关的位置信息tableLocations,即一个保存的row到RegionLocations映射的跳表结构ConcurrentSkipListMap // cachedRegionLocations也是一个ConcurrentHashMap,它是MetaCache中实现缓存Region位置信息功能所依靠的最主要的数据结构, // 它存储的是{tableName->[row->RegionLocations]}的两级映射关系 result = this.cachedRegionLocations.get(tableName); // if tableLocations for this table isn't built yet, make one if (result == null) {// 如果result没有创建的话,创建一个 result = new ConcurrentSkipListMap<byte[], RegionLocations>(Bytes.BYTES_COMPARATOR); // 将创建的result放入cachedRegionLocations,并获取旧值old ConcurrentSkipListMap<byte[], RegionLocations> old = this.cachedRegionLocations.putIfAbsent(tableName, result); // 如果old不为空,直接返回old if (old != null) { return old; } } // 返回result return result; } 注释十分详细,读者可自行分析。这里要强调的是MetaCache的一个成员变量:cachedRegionLocations,它的定义如下: /** * Map of table to table {@link HRegionLocation}s. */ private final ConcurrentMap<TableName, ConcurrentSkipListMap<byte[], RegionLocations>> cachedRegionLocations = new ConcurrentHashMap<TableName, ConcurrentSkipListMap<byte[], RegionLocations>>(); 它是MetaCache中实现缓存Region位置信息功能所依靠的最主要的数据结构,它存储的是{tableName->[row->RegionLocations]}的两级映射关系。而MetaCache中还有一个涉及到所有Server的变量,如下: // The presence of a server in the map implies it's likely that there is an // entry in cachedRegionLocations that map to this server; but the absence // of a server in this map guarentees that there is no entry in cache that // maps to the absent server. // The access to this attribute must be protected by a lock on cachedRegionLocations private final Set<ServerName> cachedServers = new ConcurrentSkipListSet<ServerName>(); 不消多说。 二、缓存获得的位置信息locations的cacheLocation()方法 有取就得有存,下面我们看下缓存获得的位置信息locations的cacheLocation()方法,代码如下: /** * Put a newly discovered HRegionLocation into the cache. * @param tableName The table name. * @param locations the new locations */ public void cacheLocation(final TableName tableName, final RegionLocations locations) { // 从Region位置信息locations中获取Region对应的起始rowkey:startKey byte [] startKey = locations.getRegionLocation().getRegionInfo().getStartKey(); // 调用getTableLocations()方法,根据表名tableName获取表的位置信息tableLocations // 它是一个Region的起始rowkey,即startKey到RegionLocations的映射 ConcurrentMap<byte[], RegionLocations> tableLocations = getTableLocations(tableName); // 将新得到的Region位置信息locations放入tableLocations,并且得到之前的Region位置信息oldLocation RegionLocations oldLocation = tableLocations.putIfAbsent(startKey, locations); // 根据oldLocation是否为null判断是否为新缓存的一个条目 boolean isNewCacheEntry = (oldLocation == null); if (isNewCacheEntry) {// 如果是新缓存的一个条目 if (LOG.isTraceEnabled()) { LOG.trace("Cached location: " + locations); } // 调用addToCachedServers()方法,缓存出现的server,加入到cachedServers列表中 addToCachedServers(locations); // 返回 return; } // 如果不是新缓存的一个条目 // merge old and new locations and add it to the cache // 合并新旧Region位置信息,并替换到缓存中 // Meta record might be stale - some (probably the same) server has closed the region // with later seqNum and told us about the new location. // 合并 RegionLocations mergedLocation = oldLocation.mergeLocations(locations); // 替换 boolean replaced = tableLocations.replace(startKey, oldLocation, mergedLocation); if (replaced && LOG.isTraceEnabled()) { LOG.trace("Merged cached locations: " + mergedLocation); } // 调用addToCachedServers()方法,缓存出现的server,加入到cachedServers列表中 addToCachedServers(locations); } 注释同样很详细,这里就不再赘述了。 三、将Result转换为我们需要的RegionLocations,即regionInfoRow->locations 接下来,我们再看下将Result转换为我们需要的RegionLocations,即regionInfoRow->locations是如何处理的。它调用的是MetaTableAccessor的getRegionLocations()方法,代码如下: /** * Returns an HRegionLocationList extracted from the result. * @return an HRegionLocationList containing all locations for the region range or null if * we can't deserialize the result. */ public static RegionLocations getRegionLocations(final Result r) { if (r == null) return null; // 从Result中获取Region信息HRegionInfo,getRegionInfoColumn()返回的为字符串"regioninfo"对应的byte[], // 也就是meta表中对应的qualifier,而family为"info" HRegionInfo regionInfo = getHRegionInfo(r, getRegionInfoColumn()); if (regionInfo == null) return null; List<HRegionLocation> locations = new ArrayList<HRegionLocation>(1); NavigableMap<byte[],NavigableMap<byte[],byte[]>> familyMap = r.getNoVersionMap(); locations.add(getRegionLocation(r, regionInfo, 0)); NavigableMap<byte[], byte[]> infoMap = familyMap.get(getFamily()); if (infoMap == null) return new RegionLocations(locations); // iterate until all serverName columns are seen int replicaId = 0; byte[] serverColumn = getServerColumn(replicaId); SortedMap<byte[], byte[]> serverMap = infoMap.tailMap(serverColumn, false); if (serverMap.isEmpty()) return new RegionLocations(locations); for (Map.Entry<byte[], byte[]> entry : serverMap.entrySet()) { replicaId = parseReplicaIdFromServerColumn(entry.getKey()); if (replicaId < 0) { break; } locations.add(getRegionLocation(r, regionInfo, replicaId)); } return new RegionLocations(locations); } 最重要的一点,从Result中获取Region信息HRegionInfo,getRegionInfoColumn()返回的为字符串"regioninfo"对应的byte[],也就是meta表中对应的qualifier,而family为"info",getHRegionInfo()和getRegionInfoColumn()方法如下: /** * Returns the column qualifier for serialized region info * @return HConstants.REGIONINFO_QUALIFIER */ protected static byte[] getRegionInfoColumn() { return HConstants.REGIONINFO_QUALIFIER; } /** * Returns the HRegionInfo object from the column {@link HConstants#CATALOG_FAMILY} and * <code>qualifier</code> of the catalog table result. * @param r a Result object from the catalog table scan * @param qualifier Column family qualifier * @return An HRegionInfo instance or null. */ private static HRegionInfo getHRegionInfo(final Result r, byte [] qualifier) { // 获取单元格Cell,family为"info",qualifier为"regioninfo" Cell cell = r.getColumnLatestCell(getFamily(), qualifier); if (cell == null) return null; // 调用HRegionInfo的parseFromOrNull()方法将Cell转换为HRegionInfo, // 实际上就是反序列化,读出HRegionInfo需要的成员变量,比如startKey、endKey、regionId、regionName、split、offLine等 return HRegionInfo.parseFromOrNull(cell.getValueArray(), cell.getValueOffset(), cell.getValueLength()); } 只有两步骤: 1、获取单元格Cell,family为"info",qualifier为"regioninfo"; 2、调用HRegionInfo的parseFromOrNull()方法将Cell转换为HRegionInfo,实际上就是反序列化,读出HRegionInfo需要的成员变量,比如startKey、endKey、regionId、regionName、split、offLine等。 四、当前线程休眠一段时间,再次重试,休眠的时间与pause和tries有关,越往后,停顿时间一般越长(波动时间除外) 最后,我们再看下当前线程休眠一段时间,再次重试,休眠的时间与pause和tries有关,越往后,停顿时间一般越长(波动时间除外)相关内容,代码如下: /** * Calculate pause time. * Built on {@link HConstants#RETRY_BACKOFF}. * @param pause * @param tries * @return How long to wait after <code>tries</code> retries */ public static long getPauseTime(final long pause, final int tries) { int ntries = tries; // 如果重试次数大于RETRY_BACKOFF的长度(即大于13),重试次数设置为12,目的是能取数组中的数值 if (ntries >= HConstants.RETRY_BACKOFF.length) { // 重试次数设置为12 ntries = HConstants.RETRY_BACKOFF.length - 1; } // 基准的停顿时间normalPause为pause * 重试次数对应在RETRY_BACKOFF数组中的位置的值; // RETRY_BACKOFF为{1, 2, 3, 5, 10, 20, 40, 100, 100, 100, 100, 200, 200} // 说明,越往后,停顿时间越长 long normalPause = pause * HConstants.RETRY_BACKOFF[ntries]; // 波动时间jitter为normalPause百分之一基础上乘以一个随机数的波动 long jitter = (long)(normalPause * RANDOM.nextFloat() * 0.01f); // 1% possible jitter // 返回基准时间加波动时间 return normalPause + jitter; } 很简单,基本上是越往后,休眠的时间越长,而pause是取参数hbase.client.pause,参数未配置的话,默认为100。 以上就是关于非Meta表,也就是业务表中row相关Region定位,实际上它还是要从Meta表中去查找的,Meta表的名字为hbase:meta,family为"info",而qualifier为"regioninfo",它也是HBase的一张表,如果从其中寻找数据的话,也是需要进行Region定位的,那么我们可以回溯到上面的那个问题了:如果是meta表,直接调用locateMeta()方法进行定位,再来看下locateMeta()方法吧,代码如下: private RegionLocations locateMeta(final TableName tableName, boolean useCache, int replicaId) throws IOException { // HBASE-10785: We cache the location of the META itself, so that we are not overloading // zookeeper with one request for every region lookup. We cache the META with empty row // key in MetaCache. // 获得meta缓存的key,实际上为byte [0] byte[] metaCacheKey = HConstants.EMPTY_START_ROW; // use byte[0] as the row for meta RegionLocations locations = null; // 如果使用缓存的话,调用getCachedLocation()方法,定位Region位置,获得RegionLocations,即locations // 如果locations不为空的话,说明缓存中存在对应数据,直接返回,否则继续往下执行,以定位Region位置 if (useCache) { locations = getCachedLocation(tableName, metaCacheKey); if (locations != null) { return locations; } } // only one thread should do the lookup. // 使用synchronized关键字在metaRegionLock上加互斥锁,确保某一时刻只有一个线程在执行 synchronized (metaRegionLock) { // Check the cache again for a hit in case some other thread made the // same query while we were waiting on the lock. // 再次检查缓存,因为可能在当前线程等待对象metaRegionLock上互斥锁的时候,一些其它线程做相同的查询 ,已经将对应数据加载入缓存 if (useCache) {// 再检查一遍缓存吧 locations = getCachedLocation(tableName, metaCacheKey); if (locations != null) { return locations; } } // Look up from zookeeper // 从zookeeper中寻找 locations = this.registry.getMetaRegionLocation(); if (locations != null) { // 定位到Region后,调用cacheLocation()方法放入缓存中,以备后续访问者可以直接从缓存中读取 cacheLocation(tableName, locations); } } return locations; } Meta表中Region的定位与非Meta表有很大不同,具体流程如下: 1、获得meta缓存的key,实际上为byte [0]; 2、如果使用缓存的话,调用getCachedLocation()方法,定位Region位置,获得RegionLocations,即locations,如果locations不为空的话,说明缓存中存在对应数据,直接返回,否则继续往下执行,以定位Region位置; 3、使用synchronized关键字在metaRegionLock上加互斥锁,确保某一时刻只有一个线程在执行: 3.1、再次检查缓存,因为可能在当前线程等待对象metaRegionLock上互斥锁的时候,一些其它线程做相同的查询 ,已经将对应数据加载入缓存; 3.2、从zookeeper中寻找Meta数据; 3.3、定位到Region后,调用cacheLocation()方法放入缓存中,以备后续访问者可以直接从缓存中读取。 这个两次从缓存中查找充分考虑了多线程等高并发环境下的数据访问情况,能够很好的考虑到性能方便的问题,确实不错! 那么Meta数据是如何从ZooKeeper中获取的呢?它是通过成员变量registry的getMetaRegionLocation()方法获取的,这个registry的初始化在HConnectionImplementation构造方法中如下: this.registry = setupRegistry(); 我们再看下这个setupRegistry()方法,代码如下: /** * @return The cluster registry implementation to use. * @throws IOException */ private Registry setupRegistry() throws IOException { return RegistryFactory.getRegistry(this); } 它调用的是RegistryFactory工厂类的静态方法getRegistry()来获得Registry实例的,我们继续往下看: /** * @return The cluster registry implementation to use. * @throws IOException */ static Registry getRegistry(final Connection connection) throws IOException { // 获取类名registryClass,取参数hbase.client.registry.impl,参数未配置的话默认为ZooKeeperRegistry String registryClass = connection.getConfiguration().get("hbase.client.registry.impl", ZooKeeperRegistry.class.getName()); Registry registry = null; try { // 通过反射获得registryClass的实例registry registry = (Registry)Class.forName(registryClass).newInstance(); } catch (Throwable t) { throw new IOException(t); } // 调用init()方法初始化registry registry.init(connection); // 返回registry return registry; } 比较简单,首先获取类名registryClass,取参数hbase.client.registry.impl,参数未配置的话默认为ZooKeeperRegistry,接着通过反射获得registryClass的实例registry,然后调用init()方法初始化registry,最后返回registry。而返回前的初始化操作也比较简单,如下: @Override public void init(Connection connection) { if (!(connection instanceof ConnectionManager.HConnectionImplementation)) { throw new RuntimeException("This registry depends on HConnectionImplementation"); } this.hci = (ConnectionManager.HConnectionImplementation)connection; } 先做connection的判断,看它是否是ConnectionManager.HConnectionImplementation实例,然后将其转化为ConnectionManager.HConnectionImplementation,并赋值给ZooKeeperRegistry的成员变量hci。 好了,知道了registry是ZooKeeperRegistry的实例了,我们就看下ZooKeeperRegistry的getMetaRegionLocation()方法吧!代码如下: @Override public RegionLocations getMetaRegionLocation() throws IOException { // 从hci中获取ZooKeeper连接ZooKeeperKeepAliveConnection,即zkw ZooKeeperKeepAliveConnection zkw = hci.getKeepAliveZooKeeperWatcher(); try { if (LOG.isTraceEnabled()) { LOG.trace("Looking up meta region location in ZK," + " connection=" + this); } // 获取ServerName:servername,通过MetaTableLocator实例的blockUntilAvailable()方法获取的 ServerName servername = new MetaTableLocator().blockUntilAvailable(zkw, hci.rpcTimeout); if (LOG.isTraceEnabled()) { LOG.trace("Looked up meta region location, connection=" + this + "; serverName=" + ((servername == null) ? "null" : servername)); } // servername为空的话,直接返回null if (servername == null) return null; // 构造HRegionLocation实例loc, // 需要的参数包括:HRegionInfo.FIRST_META_REGIONINFO、上面获得的servername和默认为0的seqNum, // HRegionInfo的FIRST_META_REGIONINFO实际上就是HRegionInfo的一个实例,其regionId为1L,TableName为TableName.META_TABLE_NAME HRegionLocation loc = new HRegionLocation(HRegionInfo.FIRST_META_REGIONINFO, servername, 0); // 利用loc构造RegionLocations,实际上RegionLocations中只包含这一个HRegionLocation return new RegionLocations(new HRegionLocation[] {loc}); } catch (InterruptedException e) { Thread.currentThread().interrupt(); return null; } finally { // 关闭zkw zkw.close(); } } getMetaRegionLocation()方法处理流程如下: 1、先从hci中获取ZooKeeper连接ZooKeeperKeepAliveConnection,即zkw; 2、获取ServerName:servername,通过MetaTableLocator实例的blockUntilAvailable()方法获取的; 3、servername为空的话,直接返回null; 4、构造HRegionLocation实例loc,需要的参数包括:HRegionInfo.FIRST_META_REGIONINFO、上面获得的servername和默认为0的seqNum,HRegionInfo的FIRST_META_REGIONINFO实际上就是HRegionInfo的一个实例,其regionId为1L,TableName为TableName.META_TABLE_NAME; 5、利用loc构造RegionLocations,实际上RegionLocations中只包含这一个HRegionLocation,并返回。 有了ServerName、HRegionInfo,那么HRegionLocation就很容易获得了。那么ServerName是如何获取的呢?我们跟踪下MetaTableLocator的blockUntilAvailable()方法,其中的关键代码为: sn = getMetaRegionLocation(zkw); if (sn != null || sw.elapsedMillis() > timeout - HConstants.SOCKET_RETRY_WAIT_MS) { break; } 而getMetaRegionLocation()方法如下: /** * Gets the meta region location, if available. Does not block. * * 如果可用的话,获取元表Region的位置。不会阻塞 * * @param zkw zookeeper connection to use * @return server name or null if we failed to get the data. */ @Nullable public ServerName getMetaRegionLocation(final ZooKeeperWatcher zkw) { try { RegionState state = getMetaRegionState(zkw); return state.isOpened() ? state.getServerName() : null; } catch (KeeperException ke) { return null; } } 而getMetaRegionState()方法关键代码如下: byte[] data = ZKUtil.getData(zkw, zkw.metaServerZNode); 它利用ZKUtil获取ZooKeeper上的metaServerZNode,而metaServerZNode的初始化如下: metaServerZNode = ZKUtil.joinZNode(baseZNode, conf.get("zookeeper.znode.metaserver", "meta-region-server")); baseZNode取参数zookeeper.znode.parent,参数未配置则默认为/hbase,然后再取参数zookeeper.znode.metaserver,参数未配置则默认为meta-region-server。也就是说,默认情况下,metaserver在ZooKeeper上的位置为/hbase/meta-region-server。 好了,到此为止,Region定位就分析完毕了。 下面,我们做个简单的总结,HBase是一个分布式数据库,对于数据的读写访问最终都是通过RowKey进行的,而要想获取数据,就必须通过指定TableName、Row来定位Region,而Region的定位,分为两种情况,一个是非Meta即用户表的定位,一个是Meta表的定位,而非Meta实际上是创建了一个ClientSmallReversedScanner从Meta表中查询的,Meta表在HBase中表名为hbase:meta,对应的family为info,qualifier为regioninfo,而问题最终归结到Meta表Region位置的定位,它是通过在ZooKeeper寻找/hbase/meta-region-server/路径下的信息来定位Meta的Server,然后通过构造一个regionId为1L,TableName为TableName.META_TABLE_NAME的HRegionInfo实例来确定Region位置信息RegionLocations的。 如有错误,或者遗漏之处,后续再做调整或补充吧!

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

Hadoop MapReduce之wordcount(词频统计)

1.创建test.log 点击(此处)折叠或打开 [root@sht-sgmhadoopnn-01 mapreduce]# more /tmp/test.log 1 2 3 a b a v a a a abc 我是谁 %…… % 2.hadoop创建目录及上传 点击(此处)折叠或打开 [root@sht-sgmhadoopnn-01 ~]# hadoop fs -mkdir /testdir 16/02/28 19:40:12 WARN util.NativeCodeLoader: Unable to load native-hadoop library for your platform... using builtin-java classes where applicable [root@sht-sgmhadoopnn-01 ~]# hadoop fs -put /tmp/test.log /testdir/ 16/02/28 19:40:19 WARN util.NativeCodeLoader: Unable to load native-hadoop library for your platform... using builtin-java classes where applicable 3.查看官方封装好的函数,我们选取wordcount 点击(此处)折叠或打开 [root@sht-sgmhadoopnn-01 ~]#cd /hadoop/hadoop-2.7.2/share/hadoop/mapreduce [root@sht-sgmhadoopnn-01 mapreduce]# hadoop jar hadoop-mapreduce-examples-2.7.2.jar An example program must be given as the first argument. Valid program names are: aggregatewordcount: An Aggregate based map/reduce program that counts the words in the input files. aggregatewordhist: An Aggregate based map/reduce program that computes the histogram of the words in the input files. bbp: A map/reduce program that uses Bailey-Borwein-Plouffe to compute exact digits of Pi. dbcount: An example job that count the pageview counts from a database. distbbp: A map/reduce program that uses a BBP-type formula to compute exact bits of Pi. grep: A map/reduce program that counts the matches of a regex in the input. join: A job that effects a join over sorted, equally partitioned datasets multifilewc: A job that counts words from several files. pentomino: A map/reduce tile laying program to find solutions to pentomino problems. pi: A map/reduce program that estimates Pi using a quasi-Monte Carlo method. randomtextwriter: A map/reduce program that writes 10GB of random textual data per node. randomwriter: A map/reduce program that writes 10GB of random data per node. secondarysort: An example defining a secondary sort to the reduce. sort: A map/reduce program that sorts the data written by the random writer. sudoku: A sudoku solver. teragen: Generate data for the terasort terasort: Run the terasort teravalidate: Checking results of terasort wordcount: A map/reduce program that counts the words in the input files. wordmean: A map/reduce program that counts the average length of the words in the input files. wordmedian: A map/reduce program that counts the median length of the words in the input files. wordstandarddeviation: A map/reduce program that counts the standard deviation of the length of the words in the input files. 4.运行wordcount # hadoop jar hadoop-mapreduce-examples-2.7.2.jar wordcount /testdir /out1 # 官方模板jar包 函数 输入目录 输出目录(未创建) 点击(此处)折叠或打开 [root@sht-sgmhadoopnn-01 mapreduce]# hadoop jar hadoop-mapreduce-examples-2.7.2.jar wordcount /testdir /out1 16/02/28 19:40:50 WARN util.NativeCodeLoader: Unable to load native-hadoop library for your platform... using builtin-java classes where applicable 16/02/28 19:40:53 INFO input.FileInputFormat: Total input paths to process : 1 16/02/28 19:40:53 INFO mapreduce.JobSubmitter: number of splits:1 16/02/28 19:40:53 INFO mapreduce.JobSubmitter: Submitting tokens for job: job_1456590271264_0002 16/02/28 19:40:54 INFO impl.YarnClientImpl: Submitted application application_1456590271264_0002 16/02/28 19:40:54 INFO mapreduce.Job: The url to track the job: http://sht-sgmhadoopnn-01:8088/proxy/application_1456590271264_0002/ 16/02/28 19:40:54 INFO mapreduce.Job: Running job: job_1456590271264_0002 16/02/28 19:41:04 INFO mapreduce.Job: Job job_1456590271264_0002 running in uber mode : false 16/02/28 19:41:04 INFO mapreduce.Job: map 0% reduce 0% 16/02/28 19:41:12 INFO mapreduce.Job: map 100% reduce 0% 16/02/28 19:41:21 INFO mapreduce.Job: map 100% reduce 100% 16/02/28 19:41:22 INFO mapreduce.Job: Job job_1456590271264_0002 completed successfully 16/02/28 19:41:22 INFO mapreduce.Job: Counters: 49 File System Counters FILE: Number of bytes read=102 FILE: Number of bytes written=244621 FILE: Number of read operations=0 FILE: Number of large read operations=0 FILE: Number of write operations=0 HDFS: Number of bytes read=142 HDFS: Number of bytes written=56 HDFS: Number of read operations=6 HDFS: Number of large read operations=0 HDFS: Number of write operations=2 Job Counters Launched map tasks=1 Launched reduce tasks=1 Data-local map tasks=1 Total time spent by all maps in occupied slots (ms)=5537 Total time spent by all reduces in occupied slots (ms)=6555 Total time spent by all map tasks (ms)=5537 Total time spent by all reduce tasks (ms)=6555 Total vcore-milliseconds taken by all map tasks=5537 Total vcore-milliseconds taken by all reduce tasks=6555 Total megabyte-milliseconds taken by all map tasks=5669888 Total megabyte-milliseconds taken by all reduce tasks=6712320 Map-Reduce Framework Map input records=12 Map output records=14 Map output bytes=100 Map output materialized bytes=102 Input split bytes=98 Combine input records=14 Combine output records=10 Reduce input groups=10 Reduce shuffle bytes=102 Reduce input records=10 Reduce output records=10 Spilled Records=20 Shuffled Maps =1 Failed Shuffles=0 Merged Map outputs=1 GC time elapsed (ms)=79 CPU time spent (ms)=2560 Physical memory (bytes) snapshot=445992960 Virtual memory (bytes) snapshot=1775263744 Total committed heap usage (bytes)=306184192 Shuffle Errors BAD_ID=0 CONNECTION=0 IO_ERROR=0 WRONG_LENGTH=0 WRONG_MAP=0 WRONG_REDUCE=0 File Input Format Counters Bytes Read=44 File Output Format Counters Bytes Written=56 You have mail in /var/spool/mail/root [root@sht-sgmhadoopnn-01 mapreduce]# 5.验证wordcount,词频统计 点击(此处)折叠或打开 [root@sht-sgmhadoopnn-01 mapreduce]# hadoop fs -ls /out1 16/02/28 19:43:21 WARN util.NativeCodeLoader: Unable to load native-hadoop library for your platform... using builtin-java classes where applicable Found 2 items -rw-r--r-- 3 root supergroup 0 2016-02-28 19:41 /out1/_SUCCESS -rw-r--r-- 3 root supergroup 56 2016-02-28 19:41 /out1/part-r-00000 [root@sht-sgmhadoopnn-01 mapreduce]# hadoop fs -text /out1/part-r-00000 16/02/28 19:43:38 WARN util.NativeCodeLoader: Unable to load native-hadoop library for your platform... using builtin-java classes where applicable % 1 %…… 1 1 1 2 1 3 1 a 5 abc 1 b 1 v 1 我是谁 1 You have mail in /var/spool/mail/root

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

Storm之Collector-p1

IBasicOutputCollector.java List<Integer> emit(String streamId, List<Object> tuple); 提交一系列的tuple,返回接收到这些tuple的taskId void emitDirect(int taskId, String streamId, List<Object> tuple); 直接向某个task提交一系列的tuple BasicOutputCollector.java 这个类里封装了一个OutputCollector的代理和一个inputTuple OutputCollector是在构造函数里传入的,在Bolt处理完tuple之后调用此类的emit方法时,方法内部会调用封装的OutputCollector来进行emit, 最终的emit是OutputCollector的emit 此类还提供了两个emit方法的重载,目的是在没有指定streamId的时候提供一个默认名为“default”的streamId. 此类的emit方法没有提供anchors参数,每次bolt执行完之后进行emit时会自动将输入tuples和输出tuples关联,如果不需要关联,则可不用此类。 IOutputCollector.java List<Integer> emit(String streamId, Collection<Tuple> anchors, List<Object> tuple); 提交一系列的tuple,返回接收到这些tuple的taskId,anchors参数是指接收到的tuples void emitDirect(int taskId, String streamId, Collection<Tuple> anchors, List<Object> tuple); 直接向某个task提交一系列tuple,同样的也会附带上输入的tuple void ack(Tuple input); ack某个tuple void fail(Tuple input); fail某个tuple OutputCollector.java 封装了一个IOutputCollector的代理,该代理在构造函数时传递进来被初始化。 提供了多个emit方法的重载,基本上包括有(单个anchor,无anchor,无指定streamId,只有输出的tuple)这些 emitDirect重载的方式也基本上一样,都是为了使用方便来做的。 当然,最终的emit,ack和fail都是通过代理来实现的。 CoordinatedOutputCollector.java 这个类比较奇葩,是定义在CoordinatedBolt的内部类,只有CoordinatedBolt这个类使用。 封装了一个IOutputCollector代理,该代理在构造函数时被初始化。 此类没有重载emit和emitDirect方法,但是在emit和emitDirect方法内部会调用一个名为updateTaskCounts的方法 private void updateTaskCounts(Object id, List<Integer> tasks) { synchronized(_tracked) { TrackingInfo track = _tracked.get(id); if (track != null) { Map<Integer, Integer> taskEmittedTuples = track.taskEmittedTuples; for(Integer task: tasks) { int newCount = get(taskEmittedTuples, task, 0) + 1; taskEmittedTuples.put(task, newCount); } } } } 这个方法主要是更新目标task和向其发送的tuple数量关系,其关系维护在_tracked变量里,关系链为 tuple_id —> task_id —> num public void ack(Tuple tuple) { Object id = tuple.getValue(0); synchronized(_tracked) { TrackingInfo track = _tracked.get(id); if (track != null) track.receivedTuples++; } boolean failed = checkFinishId(tuple, TupleType.REGULAR); if(failed) { _delegate.fail(tuple); } else { _delegate.ack(tuple); } } 将收到的tupleID对应的跟踪信息中receivedTuples(已接收数量)+1 ,然后检查是否已经处理完该tupleID对应的任务,如果检查失败就fail回上一个bolt TupleType.REGULAR是为了保证不是传递ID的也不是传递数量的流。 public void fail(Tuple tuple) { Object id = tuple.getValue(0); synchronized(_tracked) { TrackingInfo track = _tracked.get(id); if (track != null) track.failed = true; } checkFinishId(tuple, TupleType.REGULAR); _delegate.fail(tuple); } 设置跟踪信息failed,然后checkFinishId方法中会fail所有应该ack的tuples,然后删除这个tupleID对应的跟踪信息

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

Docker基础之七: 镜像操作

构建镜像 (对Docker感兴趣的朋友可以加我的微信ghostcloud2016,然后我把你加到我们的一个Docker爱好者群组里面。) 镜像(Image)是容器的基础。当你运行docker run的时候,你会指定一个Image来运行。比如,最基本的ubuntu镜像和training/webapp镜像。 在上一节中,我们是从Docker Hub下载的ubuntu镜像。在本节中,我们将做如下操作: 管理和运行你的本地镜像 创建基础镜像 1 查看本机的镜像 root@gctest:~/.ghostcloud/proxy/conf# docker images REPOSITORY TAG IMAGE ID CREATED VIRTUAL SIZE ghostcloud.cn:5005/gcali 1.0.7 553ff90cea5d 40 hours ago 219.6 MB ghostcloud.cn:5005/gcali 1.0.6 0704f2860bd6 41 hours ago 219.6 MB ghostcloud.cn:5005/gcali 1.0.3 746ac51185f2 42 hours ago 219.6 MB ghostcloud.cn:5005/gcali 1.0.2 b06108e12275 43 hours ago 219.6 MB ubuntu latest e9ae3c220b23 3 weeks ago 187.9 MB 上面你可以看到你本机的docker镜像,其中ubuntu是一个基础镜像,来自于docker hub,而ghostcloud.cn:5005/gcali是来自于ghostcloud.cn的第三方镜像。我们可以看到有几个镜像都是ghostcloud.cn:5005/gcali,但他们拥有不同的TAG,类似于版本。接下来,我们可以通过docker run来运行镜像。 root@gctest:~/.ghostcloud/proxy/conf# docker run -i -t ubuntu:latest /bin/bash root@46ffa55f5680:/# 2 获取新的image 我们如何来获取新镜像呢?其实之前我们的docker run包含了镜像的拉取,我们可以通过docker pull拉取镜像,并且不启动镜像。 $ docker pull centos Pulling repository centos b7de3133ff98: Pulling dependent layers 5cc9e91966f7: Pulling fs layer 511136ea3c5a: Download complete ef52fb1fe610: Download complete . . . Status: Downloaded newer image for centos 之后,我们可以运行这个镜像: $ docker run -t -i centos /bin/bash bash-4.1# 3 查找Image 我们可以通过docker search命令来搜索镜像,假入我们要搜索mysql: root@46ffa55f5680:/# exitroot@gctest:~/.ghostcloud/proxy/conf# docker search ubuntu NAME DESCRIPTION STARS OFFICIAL AUTOMATED ubuntu Ubuntu is a Debian-based Linux operating s... 2778 [OK] ubuntu-upstart Upstart is an event-based replacement for ... 48 [OK] dorowu/ubuntu-desktop-lxde-vnc Ubuntu with openssh-server and NoVNC on po... 28 [OK] sequenceiq/hadoop-ubuntu An easy way to try Hadoop on Ubuntu 25 [OK] torusware/speedus-ubuntu Always updated official Ubuntu docker imag... 25 [OK] ubuntu-debootstrap debootstrap --variant=minbase --components... 20 [OK] tleyden5iwx/ubuntu-cuda Ubuntu 14.04 with CUDA drivers pre-installed 18 [OK] rastasheep/ubuntu-sshd Dockerized SSH service, built on top of of... 15 [OK] consol/ubuntu-xfce-vnc Ubuntu container with "headless" VNC sessi... 7 [OK] n3ziniuka5/ubuntu-oracle-jdk Ubuntu with Oracle JDK. Check tags for ver... 5 [OK] nuagebec/ubuntu Simple always updated Ubuntu docker images... 4 [OK] ioft/armhf-ubuntu [ABR] Ubuntu Docker images for the ARMv7(a... 4 [OK] nimmis/ubuntu This is a docker images different LTS vers... 3 [OK] maxexcloo/ubuntu Docker base image built on Ubuntu with Sup... 2 [OK] densuke/ubuntu-jp-remix Ubuntu Linuxの日本語remix風味です 1 [OK] seetheprogress/ubuntu Ubuntu image provided by seetheprogress us... 1 [OK] sylvainlasnier/ubuntu Ubuntu 15.04 root docker images with commo... 1 [OK] tvaughan/ubuntu https://github.com/tvaughan/docker-ubuntu 0 [OK] rallias/ubuntu Ubuntu with the needful 0 [OK] zoni/ubuntu 0 [OK] partlab/ubuntu Simple Ubuntu docker images. 0 [OK] vicamo/ubuntu-phablet-jiexi Dockerfile for developing Ubuntu JieXi PDK. 0 [OK] densuke/ubuntu-supervisor densuke/ubuntu-jp-remix:trusty 上で supe... 0 [OK] teamrock/ubuntu TeamRock's Ubuntu image configured with AW... 0 [OK] esycat/ubuntu Ubuntu LTS 0 [OK] 4 更新自己的Image 容器实际会在Image上增加一个读写文件层,我们可以将已经运行的容器通过docker comit生成新的镜像: root@gctest:~/.ghostcloud/proxy/conf# docker ps CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES 2d961ac3b9fe ghostcloud.cn:5005/gcali:1.0.7 "/usr/local/ghostclou" 36 hours ago Up 36 hours gcsagent root@gctest:~/.ghostcloud/proxy/conf# docker commit 2d96 ghostcloud:test df9744f284bd8fd778ae7e782f2348ba24e4d9a51877c5e48b2f552fdadb526c root@gctest:~/.ghostcloud/proxy/conf# docker images REPOSITORY TAG IMAGE ID CREATED VIRTUAL SIZE ghostcloud test df9744f284bd 4 seconds ago 219.6 MB ghostcloud.cn:5005/gcali 1.0.7 553ff90cea5d 40 hours ago 219.6 MB ghostcloud.cn:5005/gcali 1.0.6 0704f2860bd6 41 hours ago 219.6 MB ghostcloud.cn:5005/gcali 1.0.3 746ac51185f2 43 hours ago 219.6 MB ghostcloud.cn:5005/gcali 1.0.2 b06108e12275 43 hours ago 219.6 MB ubuntu latest e9ae3c220b23 3 weeks ago 187.9 MB 执行命令之后,我们就有了新的镜像。因此,可以通过commit来对容器做快照,是不是很酷? 5 根据Dockerfile编译镜像 通过docker commit可以从一个已有的容器得到镜像,那么如何从头生成一个镜像呢?我们可以通过docker build来进行。首先我们创建一个Dockerfile root@gctest:~/ghostcloud# cat Dockerfile # This is a comment FROM ubuntu:latest MAINTAINER Shev Yan <yandong@ghostcloud.cn> CMD echo 'hello my image from Dockerfile.' 接着,我们进入Dockerfile所在的目录,并执行build: root@gctest:~/ghostcloud# docker build -t myimage . Sending build context to Docker daemon 2.048 kB Step 1 : FROM ubuntu:latest ---> e9ae3c220b23 Step 2 : MAINTAINER Shev Yan <yandong@ghostcloud.cn> ---> Running in 9c78817e17f1 ---> dab9385c6296 Removing intermediate container 9c78817e17f1 Step 3 : CMD echo 'hello my image from Dockerfile.' ---> Running in d8963fe120aa ---> cfcfc50fb4fb Removing intermediate container d8963fe120aa Successfully built cfcfc50fb4fb FROM: 表示源自于哪个基础镜像 MAINTAINER: 表示由谁维护 CMD: 表示镜像默认执行的命令 让我们来查看一下新生成的Image: root@gctest:~/ghostcloud# docker images REPOSITORY TAG IMAGE ID CREATED VIRTUAL SIZE myimage latest cfcfc50fb4fb About a minute ago 187.9 MB ghostcloud test df9744f284bd 5 minutes ago 219.6 MB ghostcloud.cn:5005/gcali 1.0.7 553ff90cea5d 40 hours ago 219.6 MB ghostcloud.cn:5005/gcali 1.0.6 0704f2860bd6 42 hours ago 219.6 MB ghostcloud.cn:5005/gcali 1.0.3 746ac51185f2 43 hours ago 219.6 MB ghostcloud.cn:5005/gcali 1.0.2 b06108e12275 43 hours ago 219.6 MB ubuntu latest e9ae3c220b23 3 weeks ago 187.9 MB 运行新生成的镜像: root@gctest:~/ghostcloud# docker run myimage hello my image from Dockerfile. 给Image设置tag: root@gctest:~/ghostcloud# docker tag cfcf myimage:v1 root@gctest:~/ghostcloud# docker images REPOSITORY TAG IMAGE ID CREATED VIRTUAL SIZE myimage latest cfcfc50fb4fb 8 minutes ago 187.9 MB myimage v1 cfcfc50fb4fb 8 minutes ago 187.9 MB ghostcloud test df9744f284bd 11 minutes ago 219.6 MB ghostcloud.cn:5005/gcali 1.0.7 553ff90cea5d 41 hours ago 219.6 MB ghostcloud.cn:5005/gcali 1.0.6 0704f2860bd6 42 hours ago 219.6 MB ghostcloud.cn:5005/gcali 1.0.3 746ac51185f2 43 hours ago 219.6 MB ghostcloud.cn:5005/gcali 1.0.2 b06108e12275 43 hours ago 219.6 MB ubuntu latest e9ae3c220b23 3 weeks ago 187.9 MB 6 删除Image root@gctest:~/ghostcloud# docker rmi myimage:v1 Untagged: myimage:v1

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

Docker基础之四: Docker入门

Docker入门 (对Docker感兴趣的朋友可以加我的微信ghostcloud2016,然后我把你加到我们的一个Docker爱好者群组里面。) 首先我们检查docker是否安装成功: root@gctest:~# docker info Containers: 3 Images: 18 Server Version: 1.9.0 Storage Driver: aufs Root Dir: /var/lib/docker/aufs Backing Filesystem: extfs Dirs: 24 Dirperm1 Supported: false Execution Driver: native-0.2 Logging Driver: json-file Kernel Version: 3.13.0-32-generic Operating System: Ubuntu precise (12.04.5 LTS) CPUs: 1 Total Memory: 979.2 MiB Name: gctest ID: 5RZM:ZIIU:OVNC:AS2Y:P6YZ:ZQBU:PUF2:7DR5:D3Y7:L6M5:X5RF:LQ6P WARNING: No swap limit support 如果安装成功,会显示容器数量、镜像数量、docker版本等信息。可能的失败原因有: docker: command not found 这个是安装失败,参考上一节。 /var/lib/docker/repositories: permission denied 这个可能是用户没有添加到docker组,参考上一节。 $ docker info Cannot connect to the Docker daemon. Is the docker daemon running on this host? 这个是Daemon没有启动成功。 1 下载一个镜像 # Download an ubuntu image $ docker pull Ubuntu 剖析: 该命令首先检查本地有没有ubuntu镜像,如果没有默认会从Docker Hub进行拉取 当下载成功会出现539c0211cd76: Download complete 这个ID是一个缩写的ID,完整的ID可以通过下面的命令获取docker inspect 或者docker images –no-trunc=true 2 运行一个可交互的shell终端 $ docker run -i -t ubuntu /bin/bash 剖析: -i 表示启动一个可交互的容器 –t表示使用pseudo-TTY,关联到容器的stdin和stdout 在终端中,如果输入exit命令将会停止当前容器;因此如果只是取消关联,可以键入ctrl-p或者ctrl-q 你可以在其他终端通过docker ps –a查看已经运行的容器列表 3 运行一个长时间的程序 # Start a very useful long-running process $ JOB=$(docker run -d ubuntu /bin/sh -c "while true; do echo Hello world; sleep 1; done") # Collect the output of the job so far $ docker logs $JOB # Kill the job 稍微延迟点运行 $ docker kill $JOB 剖析: 本例启动了一个容器,而该容器会每隔1秒输出Helo World –d 表示在后台运行 docker logs $JOB表示查看该容器的日志,就是查看标准输出stdout docker kill $JOB表示停掉这个容器 4 查看容器 $ docker ps # 查看运行中的容器 $ docker ps -a # 查看所有容器 5 容器操作 # 创建并启动容器 $ JOB=$(docker run -d ubuntu /bin/sh -c "while true; do echo Hello world; sleep 1; done") # 停止一个容器 $ docker stop $JOB # 启动一个已经创建的容器 $ docker start $JOB # 重启一个容器 $ docker restart $JOB # 停止一个容器 $ docker kill $JOB # 删除一个容器 $ docker stop $JOB # 必须先停止 $ docker rm $JOB 6 导出服务端口 # 将4444端口从容器导出,在容器内部通过nc监听到4444端口(nc是一个简单的监听器,可以接收用户的输入) $ JOB=$(docker run -d -p 4444 ubuntu:12.10 /bin/nc -l 4444) # 通过docker port可以查看主机上哪一个端口映射到了容器的 4444端口(docker默认使用nat映射方式) $ PORT=$(docker port $JOB 4444 | awk -F: '{ print $2 }') # 向主机的端口,发送hello world $ echo hello world | nc 127.0.0.1 $PORT # 确认容器收到了hello world $ echo "Daemon received: $(docker logs $JOB)" 剖析: nc是一个简单的监听指定端口的程序 -p表示导出容器的指定端口,由于没有指定主机端口,因此是随机分配的 外部程序可以通过主机的端口,间接访问容器的4444端口 7 提交(保存)容器到image # Commit your container to a new named image $ docker commit <container> <some_name> # List your images $ docker images 剖析: 容器运行一个Image时,是不会对image做修改的,而是在原始image上通过UnionFS增加了一个文件层用于读写,因此如果我们要想复用容器,就需要将容器commit成一个镜像。很多初学者会误以为启动一个容器后,原始镜像就会随之改变。

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

ODPS功能介绍之数据导入

在使用ODPS强大的数据处理能力之前,大家最关心的是自己的数据如何导入到ODPS中。 下面介绍一款向ODPS导入数据的工具-Fluentd。 Fluentd是一个开源的软件,用来收集各种源头日志(包括Application Log、Sys Log及Access Log),允许用户选择插件对日志数据进行过滤、并存储到不同的数据处理端(包括MySQL、Oracle、MongoDB、Hadoop、Treasure Data、AWS Services、Google Services以及ODPS等)。Fluentd以小巧灵活而著称,允许用户自定义数据源、过滤处理及目标端等插件,目前在这款软件中已经有300+个插件运行Fluentd的架构上,而且这些插件全部是开源的。 ODPS也在这款软件上开源了数据导入插件。 环境准备 使用这款软件,向ODPS导入数据,需要具备如下环境: Ruby 2.1.0 或更新 Gem 2.4.5 或更新 Fluentd-0.10.49 或从Fluentd 官网http://www.fluentd.org/ 查找最新,Fluentd为不同的OS提供了不同的版本,详见http://docs.fluentd.org/articles/quickstart Protobuf-3.5.1 或更新(Ruby protobuf) 安装导入插件 接下来可以通过以下两种方式中的任意一种来安装ODPS Fluentd 导入插件。 方式一:通过ruby gem安装: $ gem install fluent-plugin-aliyun-odps ODPS已经将这个插件发布到GEM库中, 名称为 fluent-plugin-aliyun-odps,只需要通过gem install 命令来安装即可(大家在使用gem 时在国内可能会遇到gem库无法访问,可以在网上搜一下更改gem 库源来解决)。 方式二:通过插件源码安装: $ gem install protobuf $ gem install fluentd –no-ri –no-rdoc $ git clone https://github.com/aliyun/aliyun-odps-fluentd-plugin.git $ cp aliyun-odps-fluentd-plugin/lib/fluent/plugin/* {YOUR_FLUENTD_DIRECTORY}/lib/fluent/plugin/ -r 其中第二条命令是安装fluentd,如果已经安装可以省略。 ODPS Fluentd插件源码在github上,clone下来之后直接放到Fluentd的plugin目录中即可。 插件的使用 使用Fluentd导入数据时,最主要的是配置Fluentd的conf文件,更多conf文件 的介绍请参见: http://docs.fluentd.org/articles/config-file 示例一:导入Nginx日志 。Conf中source的配置如下: <source> type tail path /opt/log/in/in.log pos_file /opt/log/in/in.log.pos refresh_interval 5s tag in.log format /^(?<remote>[^ ]*) – - \[(?<datetime>[^\]]*)\] “(?<method>\S+)(?: +(?<path>[^\"]*?)(?: +\S*)?)?” (?<code>[^ ]*) (?<size>[^ ]*) “-” “(?<agent>[^\"]*)”$/ time_format %Y%b%d %H:%M:%S %z </source> fluentd 以tail方式监控指定的文件内容是否有变化,更多的tail配置参见:http://docs.fluentd.org/articles/in_tail match 配置如下: <match in.**> type aliyun_odps aliyun_access_id ************ aliyun_access_key ********* aliyun_odps_endpoint http://service.odps.aliyun.com/api aliyun_odps_hub_endpoint http://dh.odps.aliyun.com buffer_chunk_limit 2m buffer_queue_limit 128 flush_interval 5s project projectforlog <table in.log> table nginx_log fields remote,method,path,code,size,agent partition ctime=${datetime.strftime(‘%Y%m%d’)} time_format %d/%b/%Y:%H:%M:%S %z </table> </match> 数据会导入到projectforlog project的nginx_log表中,其中会以源中的datetime字段作为分区,插件遇到不同的值时会自动创建分区; 示例二:导入MySqL中的数据。导入MySQL中数据时,需要安装fluent-plugin-sql插件作为source: $ gem install fluent-plugin-sql 配置conf中的source: <source> type sql host 127.0.0.1 database test adapter mysql username xxxx password xxxx select_interval 10s select_limit 100 state_file /path/sql_state <table> table test_table tag in.sql update_column id </table> </source> 这个例子是从test_table中SELECT数据,每间隔10s去读取100条数据出来,SELECT 时将ID列作为主键(id字段是自增型)。关于fluent-plugin-sql的更多说明参见:https://github.com/fluent/fluent-plugin-sql match 配置如下: <match in.**> type aliyun_odps aliyun_access_id ************ aliyun_access_key ********* aliyun_odps_endpoint http://service.odps.aliyun.com/api aliyun_odps_hub_endpoint http://dh.odps.aliyun.com buffer_chunk_limit 2m buffer_queue_limit 128 flush_interval 5s project your_projectforlog <table in.log> table mysql_data fields id,field1,field2,fields3 </table> </match> 数据会导出到ODPS projectforlog project的mysql_data表中,导入的字段包括id,field1,field2,field3。 关于导入表的说明 通过Fluentd导入数据是走的ODPS实时数据流入通道-Datahub,这个通道需要一个特殊的ODPS表,这个表在创建时需要指定为Hub Table。创建表时可以使用如下语名: CREATE TABLE <table_name) (field_name type,…) PARTITIONED BY (pt_name type) INTO <n1> SHARDSHUBLIFECYCLE <n2>; 其中:n1 是指shards数量,有效值为1-20。在导入数据时,每个shard的流入量是10M/秒。N2是指数据在Datahub上的保留期,有效值1-7,主要用于流计算场景中使用历史数据。 例如: createtableaccess_log(f1string,f2string,f3string,f4string,f5string,f6string,f7 string)partitionedby(ctimestring)into5shardshublifecycle7; 如果向已经存在的表导入数据,也需要将表修改为HUB表, 其命令为: ALTER TABLE table_name ENABLE HUTTABLE with <n1> SHARDS HUBLIFECYCLE <n2>; 插件参数说明 向ODPS导入数据,需要将ODPS插件配置在conf文件中match项中。插件支持的参数说明如下: type(Fixed): 固定值 aliyun_odps. aliyun_access_id(Required):云账号access_id. aliyun_access_key(Required):云账号access key. aliyun_odps_hub_endpoint(Required):如果你的服务部署在ESC上,请把本值设定为http://dh-ext.odps.aliyun-inc.com, 否则设置为http://dh.odps.aliyun.com. aliyunodps_endpoint(Required):如果你的服务部署在ESC上,请把本值设定为http://odps-ext.aiyun-inc.com/api, 否则设置为http://service.odps.aliyun.com/api. buffer_chunk_limit(Optional): 块大小,支持“k”(KB),“m”(MB),“g”(GB)单位,默认 8MB,建议值2MB. buffer_queue_limit(Optional): 块队列大小,此值与buffer_chunk_limit共同决定整个缓冲区大小。 flush_interval(Optional): 强制发送间隔,达到时间后块数据未满则强制发送, 默认 60s. project(Required): project名称. table(Required): table名称. fields(Required): 与source对应,字段名必须存在于source之中. partition(Optional):若为分区表,则设置此项. 分区名支持的设置模式: 固定值: partition ctime=20150804 关键字: partition ctime=${remote} (其中remote为source中某字段) 时间格式关键字: partition ctime=${datetime.strftime(‘%Y%m%d’)} (其中datetime为source中某时间格式字段,输出为%Y%m%d格式作为分区名称) time_format(Optional):如果使用时间格式关键字为<partition>, 请设置本参数. 例如: source[datetime]=”29/Aug/2015:11:10:16 +0800″,则设置<time_format>为”%d/%b/%Y:%H:%M:%S %z” 更多 除了使用Fluentd可以导入数据外,ODPS还支持通过Flume导入数据。Flume是Apache的一款开源软件,ODPS团队基于Flume开源了导入插件源代码,感兴趣的朋友可以参见https://github.com/aliyun/aliyun-odps-flume-plugin 了解更多细节。

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

以计算机之眼观照生活 以人工智能之慧理解人类

6月3日,“第六镜2017产品发布会”在西安市绿地笔克国际会展中心4号馆T区顺利举行。 6月3日,“第六镜2017产品发布会”在西安市绿地笔克国际会展中心4号馆T区顺利举行。现场来宾与第六镜一起见证了人工智能与计算机视觉的蓬勃发展现状,共同展望了第六镜所构想的智慧生活图景。本次发布会也由此成为向社会公众呈现先进智慧科技的窗口,并象征了以第六镜科技为代表的“丝绸之路大学生创业者联盟”的创新成果与无限潜力。 第六镜Glasssix: 以科技智慧的名义专注创新 在昨天的发布会上,“人工智能”与“计算机视觉”成为贯穿全程焦点。作为专业的模块化计算机视觉技术解决方案提供商,第六镜科技首先发布了目前全系产品中落地性最强的智慧迎宾产品——Glasssix-Hi。基于第六镜业界领先的自主核心算法及Facebeacon人脸识别服务,Glasssix-Hi以卓越的性能适用于企业前台、办公场所、商业门店、大型会展等各类实际场景,以毫秒级的极速识别支持多人同时动态人脸识别,满足用户不同的安防需求、革新现有的迎宾模式,以高端的实验室科技助力各行业的智慧化转型升级。 图为陕西省工商局副局长郑成瑞、团市委书记于海夫、西北工业大学研工部部长李春科与第六镜创始人刘闯共同触摸“第六镜2017产品发布会”启动球 长久以来,“人工智能”最引人向往之处便在于以先进的计算机科技为社会发展提供值得信赖的智慧支持,不断将日常的生活工作优化至更为理想的状态,最大限度地延伸人类能力,从而使人们在各领域更自由地探索、创造无限可能。因此,在本次活动中,第六镜科技也立足于自身在人工智能与计算机视觉方面的强大优势,关注了人们最常见的生活情景,发布了包括智慧社区、智慧校园、智慧工地及智慧展会在内的四套设计完善、专业实用的第六镜智慧场景解决方案。第六镜从这四类场景所涵盖的全部实际细节以及当前运行模式中所暴露出的关键性问题着手,以创新性的计算机科技为当下的社会生活提供了更智慧高效而又更具人性化关怀的系统性解决方案。 图为第六镜技术总监陈诗昱正在介绍Glasssix智慧校园的解决方案 同时,在当前国家大力推进“双创”事业发展的背景下,“第六镜智慧孵化器”成为本次发布会的又一亮点。针对我国创业孵化器目前的运营局限与发展瓶颈,第六镜生动详细地展示了在陕西省工商局大力支持之下、与西安团市委合作构建的3.0智慧孵化器解决方案,将破局的切入点放在了弥补创业公司或创业者个人从注册公司到承接订单、完成市场化之间的空档上,以创新思路从服务主题、培训模式、盈利模式等方面对创业孵化器经营方式进行全方位改良,使创业孵化器能真正成为支撑创业梦想起飞的坚实平台。 图为第六镜联合创始人叶雨桐正在接受陕西省电视台的采访 创新的根本始终在于在洞察未来的眼光审视现在,并从中获取灵感、付诸实践。本次发布会将第六镜的创新精神坚持到底,在最后环节中发布了第六镜科技在未来的发展规划与研发重点。 图为国家工商总局副局长甘霖女士、陕西省副省长魏增军先生莅临发布会现场 此外,国家工商总局副局长甘霖女士、陕西省副省长魏增军先生、陕西省工商局副局长郑成瑞先生、西安团市委书记于海夫先生、西北工业大学研工部部长李春科先生均莅临“第六镜2017发布会”现场,充分显示了社会各方对科技创新、青年创业的重视与鼓励,而这也将第六镜科技今后精进发展、专注创新的强效动力。 丝绸之路大学生创业者联盟: 梦想的实质是脚踏实地 “第六镜2017产品发布会”余热未退,而“丝博会智慧广告展”的多样精彩更正值进行时。这场聚集了第六镜科技、天捍航空、华航泽睿、欧卡电子智能科技及顺美传播的“强强联展”,不仅向每一个来到展会现场的观众展现着来自西北工业大学的青年创业者的别样风采,更向来自各行各业的合作伙伴传递着这群追逐梦想的青年人的实干毅力。 图为丝绸之路大学生创业联盟发起人刘闯向甘霖局长和魏增军副省长介绍联盟成员 走进绿地笔克国际会展中心4号馆T区,你一定能立刻感受到这里洋溢的热忱与活力。五家由大学生创业团队成长而来的高新企业将各自的核心产品及技术以具有交互性的方式呈现,让前来观展的来宾与最新科技进行近距离接触;以详实的数据与事实证据为每一位在展区驻足的观众解答他们对各类产品技术的疑问。 图为第六镜CPO米汀在为现场来宾讲解Glasssix智慧生活构想 而五家企业之所以能如此自信地面对观众与客户的现场直接观摩与询问,则是源于在这里的每一种产品、每一项技术都凝结着他们平日里一丝不苟的实验测试、反复推敲的改进调整,展会上展出的正是这些创业者们脚踏实地的梦想结晶。因为信得过自己的努力付出,所以现在信得过自己的产品与技术。 图为“第六镜2017产品发布会”圆满成功后团市委于海夫书记向创业者递交开始创业之门金钥匙,并与丝绸之路大学生创业联盟成员合影留念 “丝博会智慧广告展”还将持续到6月7日,这场前沿科技的盛宴正在时刻以最完美的状态期待你的到来! 原文发布时间: 2017-06-05 00:20 本文来自云栖社区合作伙伴镁客网,了解相关信息可以关注镁客网。

资源下载

更多资源
优质分享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等操作系统。

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