public static void clipDBWithKeyGroupRange(
            @Nonnull RocksDB db,
            @Nonnull List<ColumnFamilyHandle> columnFamilyHandles,
            @Nonnull KeyGroupRange targetKeyGroupRange,
            @Nonnull KeyGroupRange currentKeyGroupRange,
            @Nonnegative int keyGroupPrefixBytes,
            boolean useDeleteFilesInRange)
            throws RocksDBException {

        List<byte[]> deleteFilesRanges = new ArrayList<>(4);

        if (currentKeyGroupRange.getStartKeyGroup() < targetKeyGroupRange.getStartKeyGroup()) {
            prepareRangeDeletes(
                    keyGroupPrefixBytes,
                    currentKeyGroupRange.getStartKeyGroup(),
                    targetKeyGroupRange.getStartKeyGroup(),
                    deleteFilesRanges);
        }

        if (currentKeyGroupRange.getEndKeyGroup() > targetKeyGroupRange.getEndKeyGroup()) {
            prepareRangeDeletes(
                    keyGroupPrefixBytes,
                    targetKeyGroupRange.getEndKeyGroup() + 1,
                    currentKeyGroupRange.getEndKeyGroup() + 1,
                    deleteFilesRanges);
        }

        logger.info(
                "Performing range delete for backend with target key-groups range {} with boundaries set {} - deleteFilesInRanges = {}.",
                targetKeyGroupRange.prettyPrintInterval(),
                deleteFilesRanges.stream().map(Arrays::toString).collect(Collectors.toList()),
                useDeleteFilesInRange);

        deleteRangeData(db, columnFamilyHandles, deleteFilesRanges, useDeleteFilesInRange);
    }
@Test
    public void testClipDBWithKeyGroupRange() throws Exception {

        testClipDBWithKeyGroupRangeHelper(new KeyGroupRange(0, 1), new KeyGroupRange(0, 2), 1);

        testClipDBWithKeyGroupRangeHelper(new KeyGroupRange(0, 1), new KeyGroupRange(0, 1), 1);

        testClipDBWithKeyGroupRangeHelper(new KeyGroupRange(0, 1), new KeyGroupRange(1, 2), 1);

        testClipDBWithKeyGroupRangeHelper(new KeyGroupRange(0, 1), new KeyGroupRange(2, 4), 1);

        testClipDBWithKeyGroupRangeHelper(new KeyGroupRange(4, 5), new KeyGroupRange(2, 7), 1);

        testClipDBWithKeyGroupRangeHelper(
                new KeyGroupRange(Byte.MAX_VALUE - 15, Byte.MAX_VALUE),
                new KeyGroupRange(Byte.MAX_VALUE - 10, Byte.MAX_VALUE),
                1);

        testClipDBWithKeyGroupRangeHelper(
                new KeyGroupRange(Short.MAX_VALUE - 15, Short.MAX_VALUE),
                new KeyGroupRange(Short.MAX_VALUE - 10, Short.MAX_VALUE),
                2);

        testClipDBWithKeyGroupRangeHelper(
                new KeyGroupRange(Byte.MAX_VALUE - 15, Byte.MAX_VALUE - 1),
                new KeyGroupRange(Byte.MAX_VALUE - 10, Byte.MAX_VALUE),
                1);

        testClipDBWithKeyGroupRangeHelper(
                new KeyGroupRange(Short.MAX_VALUE - 15, Short.MAX_VALUE - 1),
                new KeyGroupRange(Short.MAX_VALUE - 10, Short.MAX_VALUE),
                2);
    }