com.gemstone.gemfire.internal.cache.persistence.soplog.NonCompactor Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of gemfire-core Show documentation
Show all versions of gemfire-core Show documentation
SnappyData store based off Pivotal GemFireXD
The newest version!
/*
* Copyright (c) 2010-2015 Pivotal Software, Inc. All rights reserved.
*
* Licensed under the Apache License, Version 2.0 (the "License"); you
* may not use this file except in compliance with the License. You
* may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
* implied. See the License for the specific language governing
* permissions and limitations under the License. See accompanying
* LICENSE file.
*/
package com.gemstone.gemfire.internal.cache.persistence.soplog;
import java.io.File;
import java.io.IOException;
import java.util.ArrayDeque;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Deque;
import java.util.SortedMap;
import java.util.TreeMap;
import java.util.concurrent.atomic.AtomicLong;
import com.gemstone.gemfire.internal.cache.persistence.soplog.SortedOplog.SortedOplogReader;
/**
* Provides a compactor that does no compaction, primarily for testing purposes.
*
* @author bakera
*/
public class NonCompactor implements Compactor {
/** the fileset */
private final Fileset fileset;
/** the current readers */
private final Deque> readers;
public static Fileset createFileset(final String name, final File dir) {
return new Fileset() {
private final AtomicLong file = new AtomicLong(0);
@Override
public SortedMap> recover() {
return new TreeMap>();
}
@Override
public File getNextFilename() {
return new File(dir, name + "-" + System.currentTimeMillis() + "-"
+ file.getAndIncrement() + ".soplog");
}
};
}
public NonCompactor(String name, File dir) {
fileset = createFileset(name, dir);
readers = new ArrayDeque>();
}
@Override
public boolean compact() throws IOException {
// liar!
return true;
}
@Override
public void compact(boolean force, CompactionHandler cd) {
}
@Override
public synchronized Collection> getActiveReaders(
byte[] start, byte[] end) {
for (TrackedReference tr : readers) {
tr.increment();
}
return new ArrayList>(readers);
}
@Override
public void add(SortedOplog soplog) throws IOException {
readers.addFirst(new TrackedReference(soplog.createReader()));
}
@Override
public synchronized void clear() throws IOException {
for (TrackedReference tr : readers) {
tr.get().close();
readers.remove(tr);
}
}
@Override
public synchronized void close() throws IOException {
clear();
}
@Override
public CompactionTracker getTracker() {
return null;
}
@Override
public Fileset getFileset() {
return fileset;
}
}