@Override public boolean visit(Result r) throws IOException { if (r == null || r.isEmpty()) return true; // Check info:regioninfo, info:splitA, and info:splitB. Make sure all // have migrated HRegionInfos... that there are no leftover 090 version // HRegionInfos. byte [] hriBytes = getBytes(r, HConstants.REGIONINFO_QUALIFIER); // Presumes that an edit updating all three cells either succeeds or // doesn't -- that we don't have case of info:regioninfo migrated but not // info:splitA. if (isMigrated(hriBytes)) return true; // OK. Need to migrate this row in meta. HRegionInfo090x hri090 = getHRegionInfo090x(hriBytes); HTableDescriptor htd = hri090.getTableDesc(); if (htd == null) { LOG.warn("A 090 HRI has null HTD? Continuing; " + hri090.toString()); return true; } if (!this.htds.contains(htd)) { // If first time we are adding a table, then write it out to fs. // Presumes that first region in table has THE table's schema which // might not be too bad of a presumption since it'll be first region // 'altered' this.services.getMasterFileSystem().createTableDescriptor(htd); this.htds.add(htd); } // This will 'migrate' the hregioninfo from 090 version to 092. HRegionInfo hri = new HRegionInfo(hri090); // Now make a put to write back to meta. Put p = new Put(hri.getRegionName()); p.add(HConstants.CATALOG_FAMILY, HConstants.REGIONINFO_QUALIFIER, Writables.getBytes(hri)); // Now check info:splitA and info:splitB if present. Migrate these too. checkSplit(r, p, HConstants.SPLITA_QUALIFIER); checkSplit(r, p, HConstants.SPLITB_QUALIFIER); // Below we fake out putToCatalogTable MetaEditor.putToCatalogTable(this.services.getCatalogTracker(), p); LOG.info("Migrated " + Bytes.toString(p.getRow())); return true; }
/** * @param r Result to look in. * @param qualifier What to look at in the passed result. * @return Either a 090 vintage HRegionInfo OR null if no HRegionInfo or * the HRegionInfo is up to date and not in need of migration. * @throws IOException */ static HRegionInfo090x get090HRI(final Result r, final byte [] qualifier) throws IOException { byte [] hriBytes = r.getValue(HConstants.CATALOG_FAMILY, qualifier); if (hriBytes == null || hriBytes.length <= 0) return null; if (isMigrated(hriBytes)) return null; return getHRegionInfo090x(hriBytes); }
/** * Used only for migration * @param other HRegionInfoForMigration */ public HRegionInfo(HRegionInfo090x other) { super(); this.endKey = other.getEndKey(); this.offLine = other.isOffline(); this.regionId = other.getRegionId(); this.regionName = other.getRegionName(); this.regionNameStr = Bytes.toStringBinary(this.regionName); this.split = other.isSplit(); this.startKey = other.getStartKey(); this.hashCode = other.hashCode(); this.encodedName = other.getEncodedName(); this.tableName = other.getTableDesc().getName(); }
/** * @param c * @param htd * @param columnFamily * @param startKeys * @return * @throws IOException * @deprecated Just for testing migration of meta from 0.90 to 0.92... will be * removed thereafter */ public int createMultiRegionsWithLegacyHRI(final Configuration c, final HTableDescriptor htd, final byte[] columnFamily, byte [][] startKeys) throws IOException { Arrays.sort(startKeys, Bytes.BYTES_COMPARATOR); HTable meta = new HTable(c, HConstants.META_TABLE_NAME); if(!htd.hasFamily(columnFamily)) { HColumnDescriptor hcd = new HColumnDescriptor(columnFamily); htd.addFamily(hcd); } List<HRegionInfo090x> newRegions = new ArrayList<HRegionInfo090x>(startKeys.length); int count = 0; for (int i = 0; i < startKeys.length; i++) { int j = (i + 1) % startKeys.length; HRegionInfo090x hri = new HRegionInfo090x(htd, startKeys[i], startKeys[j]); Put put = new Put(hri.getRegionName()); put.setWriteToWAL(false); put.add(HConstants.CATALOG_FAMILY, HConstants.REGIONINFO_QUALIFIER, Writables.getBytes(hri)); meta.put(put); LOG.info("createMultiRegions: PUT inserted " + hri.toString()); newRegions.add(hri); count++; } meta.close(); return count; }