Search in sources :

Example 1 with EMPTY_BYTE_ARRAY

use of org.apache.commons.lang3.ArrayUtils.EMPTY_BYTE_ARRAY in project hbase by apache.

the class RegionProcedureStore method tryMigrate.

@SuppressWarnings("deprecation")
private void tryMigrate(FileSystem fs) throws IOException {
    Configuration conf = server.getConfiguration();
    Path procWALDir = new Path(CommonFSUtils.getWALRootDir(conf), WALProcedureStore.MASTER_PROCEDURE_LOGDIR);
    if (!fs.exists(procWALDir)) {
        return;
    }
    LOG.info("The old WALProcedureStore wal directory {} exists, migrating...", procWALDir);
    WALProcedureStore store = new WALProcedureStore(conf, leaseRecovery);
    store.start(numThreads);
    store.recoverLease();
    MutableLong maxProcIdSet = new MutableLong(-1);
    List<Procedure<?>> procs = new ArrayList<>();
    Map<Class<?>, List<Procedure<?>>> activeProcsByType = new HashMap<>();
    store.load(new ProcedureLoader() {

        @Override
        public void setMaxProcId(long maxProcId) {
            maxProcIdSet.setValue(maxProcId);
        }

        @Override
        public void load(ProcedureIterator procIter) throws IOException {
            while (procIter.hasNext()) {
                Procedure<?> proc = procIter.next();
                procs.add(proc);
                if (!proc.isFinished()) {
                    activeProcsByType.computeIfAbsent(proc.getClass(), k -> new ArrayList<>()).add(proc);
                }
            }
        }

        @Override
        public void handleCorrupted(ProcedureIterator procIter) throws IOException {
            long corruptedCount = 0;
            while (procIter.hasNext()) {
                LOG.error("Corrupted procedure {}", procIter.next());
                corruptedCount++;
            }
            if (corruptedCount > 0) {
                throw new IOException("There are " + corruptedCount + " corrupted procedures when" + " migrating from the old WAL based store to the new region based store, please" + " fix them before upgrading again.");
            }
        }
    });
    // check whether there are unsupported procedures, this could happen when we are migrating from
    // 2.1-. We used to do this in HMaster, after loading all the procedures from procedure store,
    // but here we have to do it before migrating, otherwise, if we find some unsupported
    // procedures, the users can not go back to 2.1 to finish them any more, as all the data are now
    // in the new region based procedure store, which is not supported in 2.1-.
    checkUnsupportedProcedure(activeProcsByType);
    MutableLong maxProcIdFromProcs = new MutableLong(-1);
    for (Procedure<?> proc : procs) {
        update(proc);
        if (proc.getProcId() > maxProcIdFromProcs.longValue()) {
            maxProcIdFromProcs.setValue(proc.getProcId());
        }
    }
    LOG.info("Migrated {} existing procedures from the old storage format.", procs.size());
    LOG.info("The WALProcedureStore max pid is {}, and the max pid of all loaded procedures is {}", maxProcIdSet.longValue(), maxProcIdFromProcs.longValue());
    // anyway, let's do a check here.
    if (maxProcIdSet.longValue() > maxProcIdFromProcs.longValue()) {
        if (maxProcIdSet.longValue() > 0) {
            // let's add a fake row to retain the max proc id
            region.update(r -> r.put(new Put(Bytes.toBytes(maxProcIdSet.longValue())).addColumn(PROC_FAMILY, PROC_QUALIFIER, EMPTY_BYTE_ARRAY)));
        }
    } else if (maxProcIdSet.longValue() < maxProcIdFromProcs.longValue()) {
        LOG.warn("The WALProcedureStore max pid is less than the max pid of all loaded procedures");
    }
    store.stop(false);
    if (!fs.delete(procWALDir, true)) {
        throw new IOException("Failed to delete the WALProcedureStore migrated proc wal directory " + procWALDir);
    }
    LOG.info("Migration of WALProcedureStore finished");
}
Also used : Path(org.apache.hadoop.fs.Path) Configuration(org.apache.hadoop.conf.Configuration) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) IOException(java.io.IOException) UncheckedIOException(java.io.UncheckedIOException) HBaseIOException(org.apache.hadoop.hbase.HBaseIOException) Put(org.apache.hadoop.hbase.client.Put) MutableLong(org.apache.commons.lang3.mutable.MutableLong) UnassignProcedure(org.apache.hadoop.hbase.master.assignment.UnassignProcedure) RecoverMetaProcedure(org.apache.hadoop.hbase.master.procedure.RecoverMetaProcedure) Procedure(org.apache.hadoop.hbase.procedure2.Procedure) AssignProcedure(org.apache.hadoop.hbase.master.assignment.AssignProcedure) MoveRegionProcedure(org.apache.hadoop.hbase.master.assignment.MoveRegionProcedure) ServerCrashProcedure(org.apache.hadoop.hbase.master.procedure.ServerCrashProcedure) ArrayList(java.util.ArrayList) List(java.util.List) WALProcedureStore(org.apache.hadoop.hbase.procedure2.store.wal.WALProcedureStore)

Example 2 with EMPTY_BYTE_ARRAY

use of org.apache.commons.lang3.ArrayUtils.EMPTY_BYTE_ARRAY in project neo4j by neo4j.

the class AppendOnlyValuesContainerTest method addGet.

@TestFactory
Stream<DynamicTest> addGet() {
    final List<Pair<String, Value[]>> inputs = asList(testInput("NoValue", Function.identity(), Values.NO_VALUE), testInput("Boolean", Values::booleanValue, true, false, true, false), testInput("BooleanArray", Values::booleanArray, new boolean[] { false, true, false }, EMPTY_BOOLEAN_ARRAY), testInput("Byte", Values::byteValue, (byte) 0, (byte) 1, (byte) -1, Byte.MIN_VALUE, Byte.MAX_VALUE), testInput("ByteArray", Values::byteArray, new byte[] { (byte) 0, (byte) 1, (byte) -1, Byte.MIN_VALUE, Byte.MAX_VALUE }, EMPTY_BYTE_ARRAY), testInput("Short", Values::shortValue, (short) 0, (short) 1, (short) -1, Short.MIN_VALUE, Short.MAX_VALUE), testInput("ShortArray", Values::shortArray, new short[] { (short) 0, (short) 1, (short) -1, Short.MIN_VALUE, Short.MAX_VALUE }, EMPTY_SHORT_ARRAY), testInput("Char", Values::charValue, 'a', '\uFFFF', '∂', '©'), testInput("CharArray", Values::charArray, new char[] { 'a', '\uFFFF', '∂', '©' }, EMPTY_CHAR_ARRAY), testInput("Int", Values::intValue, 0, 1, -1, Integer.MIN_VALUE, Integer.MAX_VALUE), testInput("IntArray", Values::intArray, new int[] { 0, 1, -1, Integer.MIN_VALUE, Integer.MAX_VALUE }, EMPTY_INT_ARRAY), testInput("Long", Values::longValue, 0L, 1L, -1L, Long.MIN_VALUE, Long.MAX_VALUE), testInput("LongArray", Values::longArray, new long[] { 0L, 1L, -1L, Long.MIN_VALUE, Long.MAX_VALUE }, EMPTY_LONG_ARRAY), testInput("Double", Values::doubleValue, 0.0, 1.0, -1.0, Double.MIN_VALUE, Double.MAX_VALUE, Double.NEGATIVE_INFINITY, Double.POSITIVE_INFINITY), testInput("DoubleArray", Values::doubleArray, new double[] { 0.0, 1.0, -1.0, Double.MIN_VALUE, Double.MAX_VALUE, Double.NEGATIVE_INFINITY, Double.POSITIVE_INFINITY }, EMPTY_DOUBLE_ARRAY), testInput("Float", Values::floatValue, 0.0f, 1.0f, -1.0f, Float.MIN_VALUE, Float.MAX_VALUE, Float.NEGATIVE_INFINITY, Float.POSITIVE_INFINITY), testInput("FloatArray", Values::floatArray, new float[] { 0.0f, 1.0f, -1.0f, Float.MIN_VALUE, Float.MAX_VALUE, Float.NEGATIVE_INFINITY, Float.POSITIVE_INFINITY }, EMPTY_FLOAT_ARRAY), testInput("String", Values::stringValue, "", "x", "foobar"), testInput("StringArray", Values::stringArray, new String[] { "", "x", "foobar" }, EMPTY_STRING_ARRAY), testInput("Point", input -> pointValue(input.getOne(), input.getTwo()), Tuples.pair(CoordinateReferenceSystem.WGS84, new double[] { 1.0, 2.0 }), Tuples.pair(CoordinateReferenceSystem.WGS84_3D, new double[] { 1.0, 2.0, 3.0 }), Tuples.pair(CoordinateReferenceSystem.Cartesian, new double[] { 1.0, 2.0 }), Tuples.pair(CoordinateReferenceSystem.Cartesian_3D, new double[] { 1.0, 2.0, 3.0 })), testInput("PointArray", Values::pointArray, new Point[] { pointValue(CoordinateReferenceSystem.WGS84, 1.0, 2.0), pointValue(CoordinateReferenceSystem.WGS84_3D, 1.0, 2.0, 3.0), pointValue(CoordinateReferenceSystem.Cartesian, 1.0, 2.0), pointValue(CoordinateReferenceSystem.Cartesian_3D, 1.0, 2.0, 3.0) }, new Point[0]), testInput("Duration", Values::durationValue, (TemporalAmount) Duration.parse("P2DT3H4M"), Period.parse("P1Y2M3W4D")), testInput("DurationArray", Values::durationArray, new TemporalAmount[] { Duration.parse("P2DT3H4M"), Period.parse("P1Y2M3W4D") }, new TemporalAmount[0]), testInput("Date", DateValue::date, LocalDate.now(), LocalDate.parse("1977-05-25")), testInput("DateArray", Values::dateArray, new LocalDate[] { LocalDate.now(), LocalDate.parse("1977-05-25") }, new LocalDate[0]), testInput("Time", TimeValue::time, OffsetTime.now(), OffsetTime.parse("19:28:34.123+02:00")), testInput("TimeArray", Values::timeArray, new OffsetTime[] { OffsetTime.now(), OffsetTime.parse("19:28:34.123+02:00") }, new OffsetTime[0]), testInput("LocalTime", LocalTimeValue::localTime, LocalTime.now(), LocalTime.parse("19:28:34.123")), testInput("LocalTimeArray", Values::localTimeArray, new LocalTime[] { LocalTime.now(), LocalTime.parse("19:28:34.123") }, new LocalTime[0]), testInput("LocalDateTime", LocalDateTimeValue::localDateTime, LocalDateTime.now(), LocalDateTime.parse("1956-10-04T19:28:34.123")), testInput("LocalDateTimeArray", Values::localDateTimeArray, new LocalDateTime[] { LocalDateTime.now(), LocalDateTime.parse("1956-10-04T19:28:34.123") }, new LocalDateTime[0]), testInput("DateTime", DateTimeValue::datetime, ZonedDateTime.now(), ZonedDateTime.parse("1956-10-04T19:28:34.123+01:00[Europe/Paris]"), ZonedDateTime.parse("1956-10-04T19:28:34.123+01:15"), ZonedDateTime.parse("2018-09-13T16:12:16.12345+14:00[Pacific/Kiritimati]"), ZonedDateTime.parse("2018-09-13T16:12:16.12345-12:00[Etc/GMT+12]"), ZonedDateTime.parse("2018-09-13T16:12:16.12345-18:00"), ZonedDateTime.parse("2018-09-13T16:12:16.12345+18:00")), testInput("DateTimeArray", Values::dateTimeArray, new ZonedDateTime[] { ZonedDateTime.parse("1956-10-04T19:28:34.123+01:00[Europe/Paris]"), ZonedDateTime.parse("1956-10-04T19:28:34.123+01:15"), ZonedDateTime.parse("2018-09-13T16:12:16.12345+14:00[Pacific/Kiritimati]"), ZonedDateTime.parse("2018-09-13T16:12:16.12345-12:00[Etc/GMT+12]"), ZonedDateTime.parse("2018-09-13T16:12:16.12345-18:00"), ZonedDateTime.parse("2018-09-13T16:12:16.12345+18:00") }, new ZonedDateTime[0]));
    return DynamicTest.stream(inputs.iterator(), Pair::getOne, pair -> {
        final Value[] values = pair.getTwo();
        final long[] refs = Arrays.stream(values).mapToLong(container::add).toArray();
        for (int i = 0; i < values.length; i++) {
            assertEquals(values[i], container.get(refs[i]));
        }
    });
}
Also used : Arrays(java.util.Arrays) TestFactory(org.junit.jupiter.api.TestFactory) RandomExtension(org.neo4j.test.extension.RandomExtension) ZonedDateTime(java.time.ZonedDateTime) Value(org.neo4j.values.storable.Value) LocalMemoryTracker(org.neo4j.memory.LocalMemoryTracker) MutableList(org.eclipse.collections.api.list.MutableList) EMPTY_BYTE_ARRAY(org.apache.commons.lang3.ArrayUtils.EMPTY_BYTE_ARRAY) AfterAll(org.junit.jupiter.api.AfterAll) EMPTY_CHAR_ARRAY(org.apache.commons.lang3.ArrayUtils.EMPTY_CHAR_ARRAY) Values.longValue(org.neo4j.values.storable.Values.longValue) ExtendWith(org.junit.jupiter.api.extension.ExtendWith) EMPTY_BOOLEAN_ARRAY(org.apache.commons.lang3.ArrayUtils.EMPTY_BOOLEAN_ARRAY) RandomRule(org.neo4j.test.rule.RandomRule) Arrays.asList(java.util.Arrays.asList) Duration(java.time.Duration) Tuples(org.eclipse.collections.impl.tuple.Tuples) LocalTime(java.time.LocalTime) OffsetTime(java.time.OffsetTime) Test(org.junit.jupiter.api.Test) LocalDateTimeValue(org.neo4j.values.storable.LocalDateTimeValue) List(java.util.List) Stream(java.util.stream.Stream) TimeValue(org.neo4j.values.storable.TimeValue) EMPTY_FLOAT_ARRAY(org.apache.commons.lang3.ArrayUtils.EMPTY_FLOAT_ARRAY) ObjectLongPair(org.eclipse.collections.api.tuple.primitive.ObjectLongPair) DateTimeValue(org.neo4j.values.storable.DateTimeValue) Values.intValue(org.neo4j.values.storable.Values.intValue) LocalDate(java.time.LocalDate) CachingOffHeapBlockAllocator(org.neo4j.kernel.impl.util.collection.CachingOffHeapBlockAllocator) EMPTY_SHORT_ARRAY(org.apache.commons.lang3.ArrayUtils.EMPTY_SHORT_ARRAY) EMPTY_LONG_ARRAY(org.apache.commons.lang3.ArrayUtils.EMPTY_LONG_ARRAY) Assertions.assertThrows(org.junit.jupiter.api.Assertions.assertThrows) EMPTY_DOUBLE_ARRAY(org.apache.commons.lang3.ArrayUtils.EMPTY_DOUBLE_ARRAY) LocalDateTime(java.time.LocalDateTime) EmptyMemoryTracker(org.neo4j.memory.EmptyMemoryTracker) Function(java.util.function.Function) FastList(org.eclipse.collections.impl.list.mutable.FastList) ArrayList(java.util.ArrayList) Values(org.neo4j.values.storable.Values) Values.pointValue(org.neo4j.values.storable.Values.pointValue) Inject(org.neo4j.test.extension.Inject) PrimitiveTuples.pair(org.eclipse.collections.impl.tuple.primitive.PrimitiveTuples.pair) TemporalAmount(java.time.temporal.TemporalAmount) Point(org.neo4j.graphdb.spatial.Point) Assertions.assertEquals(org.junit.jupiter.api.Assertions.assertEquals) Pair(org.eclipse.collections.api.tuple.Pair) LocalTimeValue(org.neo4j.values.storable.LocalTimeValue) MemoryTracker(org.neo4j.memory.MemoryTracker) EMPTY_INT_ARRAY(org.apache.commons.lang3.ArrayUtils.EMPTY_INT_ARRAY) Period(java.time.Period) OffHeapMemoryAllocator(org.neo4j.kernel.impl.util.collection.OffHeapMemoryAllocator) Values.stringValue(org.neo4j.values.storable.Values.stringValue) AfterEach(org.junit.jupiter.api.AfterEach) EMPTY_STRING_ARRAY(org.apache.commons.lang3.ArrayUtils.EMPTY_STRING_ARRAY) CoordinateReferenceSystem(org.neo4j.values.storable.CoordinateReferenceSystem) DateValue(org.neo4j.values.storable.DateValue) DynamicTest(org.junit.jupiter.api.DynamicTest) LocalDateTime(java.time.LocalDateTime) LocalTime(java.time.LocalTime) Point(org.neo4j.graphdb.spatial.Point) LocalDate(java.time.LocalDate) Point(org.neo4j.graphdb.spatial.Point) ZonedDateTime(java.time.ZonedDateTime) OffsetTime(java.time.OffsetTime) TemporalAmount(java.time.temporal.TemporalAmount) Value(org.neo4j.values.storable.Value) Values.longValue(org.neo4j.values.storable.Values.longValue) LocalDateTimeValue(org.neo4j.values.storable.LocalDateTimeValue) TimeValue(org.neo4j.values.storable.TimeValue) DateTimeValue(org.neo4j.values.storable.DateTimeValue) Values.intValue(org.neo4j.values.storable.Values.intValue) Values.pointValue(org.neo4j.values.storable.Values.pointValue) LocalTimeValue(org.neo4j.values.storable.LocalTimeValue) Values.stringValue(org.neo4j.values.storable.Values.stringValue) DateValue(org.neo4j.values.storable.DateValue) ObjectLongPair(org.eclipse.collections.api.tuple.primitive.ObjectLongPair) Pair(org.eclipse.collections.api.tuple.Pair) TestFactory(org.junit.jupiter.api.TestFactory)

Aggregations

ArrayList (java.util.ArrayList)2 List (java.util.List)2 IOException (java.io.IOException)1 UncheckedIOException (java.io.UncheckedIOException)1 Duration (java.time.Duration)1 LocalDate (java.time.LocalDate)1 LocalDateTime (java.time.LocalDateTime)1 LocalTime (java.time.LocalTime)1 OffsetTime (java.time.OffsetTime)1 Period (java.time.Period)1 ZonedDateTime (java.time.ZonedDateTime)1 TemporalAmount (java.time.temporal.TemporalAmount)1 Arrays (java.util.Arrays)1 Arrays.asList (java.util.Arrays.asList)1 HashMap (java.util.HashMap)1 Function (java.util.function.Function)1 Stream (java.util.stream.Stream)1 EMPTY_BOOLEAN_ARRAY (org.apache.commons.lang3.ArrayUtils.EMPTY_BOOLEAN_ARRAY)1 EMPTY_BYTE_ARRAY (org.apache.commons.lang3.ArrayUtils.EMPTY_BYTE_ARRAY)1 EMPTY_CHAR_ARRAY (org.apache.commons.lang3.ArrayUtils.EMPTY_CHAR_ARRAY)1