* stable-5.6: reftable: don't check deadline on the first try reftable: clarify comment reftable: clear cache on full compaction reftable: remove outdated comment reftable: clarify that LogCursor may return a null ReflogEntry Change-Id: I9458a746311984fa687b3da964805e2568ed37f3tags/v5.7.0.202002241735-m3
import java.io.File; | import java.io.File; | ||||
import java.io.IOException; | import java.io.IOException; | ||||
import java.security.SecureRandom; | |||||
import java.util.ArrayList; | import java.util.ArrayList; | ||||
import java.util.List; | import java.util.List; | ||||
assertEquals(RefUpdate.Result.LOCK_FAILURE, rename.rename()); | assertEquals(RefUpdate.Result.LOCK_FAILURE, rename.rename()); | ||||
} | } | ||||
@Test | |||||
public void compactFully() throws Exception { | |||||
FileReftableDatabase refDb = (FileReftableDatabase) db.getRefDatabase(); | |||||
PersonIdent person = new PersonIdent("jane", "jane@invalid"); | |||||
ObjectId aId = db.exactRef("refs/heads/a").getObjectId(); | |||||
ObjectId bId = db.exactRef("refs/heads/b").getObjectId(); | |||||
SecureRandom random = new SecureRandom(); | |||||
List<String> strs = new ArrayList<>(); | |||||
for (int i = 0; i < 1024; i++) { | |||||
strs.add(String.format("%02x", | |||||
Integer.valueOf(random.nextInt(256)))); | |||||
} | |||||
String randomStr = String.join("", strs); | |||||
String refName = "branch"; | |||||
for (long i = 0; i < 2; i++) { | |||||
RefUpdate ru = refDb.newUpdate(refName, false); | |||||
ru.setNewObjectId(i % 2 == 0 ? aId : bId); | |||||
ru.setForceUpdate(true); | |||||
// Only write a large string in the first table, so it becomes much larger | |||||
// than the second, and the result is not autocompacted. | |||||
ru.setRefLogMessage(i == 0 ? randomStr : "short", false); | |||||
ru.setRefLogIdent(person); | |||||
RefUpdate.Result res = ru.update(); | |||||
assertTrue(res == Result.NEW || res == FORCED); | |||||
} | |||||
assertEquals(refDb.exactRef(refName).getObjectId(), bId); | |||||
assertTrue(randomStr.equals(refDb.getReflogReader(refName).getReverseEntry(1).getComment())); | |||||
refDb.compactFully(); | |||||
assertEquals(refDb.exactRef(refName).getObjectId(), bId); | |||||
assertTrue(randomStr.equals(refDb.getReflogReader(refName).getReverseEntry(1).getComment())); | |||||
} | |||||
@Test | @Test | ||||
public void reftableRefsStorageClass() throws IOException { | public void reftableRefsStorageClass() throws IOException { | ||||
Ref b = db.exactRef("refs/heads/b"); | Ref b = db.exactRef("refs/heads/b"); |
reftableDatabase.getLock().lock(); | reftableDatabase.getLock().lock(); | ||||
try { | try { | ||||
reftableStack.compactFully(); | reftableStack.compactFully(); | ||||
reftableDatabase.clearCache(); | |||||
} finally { | } finally { | ||||
reftableDatabase.getLock().unlock(); | reftableDatabase.getLock().unlock(); | ||||
} | } |
long max = 1000; | long max = 1000; | ||||
long delay = 0; | long delay = 0; | ||||
boolean success = false; | boolean success = false; | ||||
while (System.currentTimeMillis() < deadline) { | |||||
// Don't check deadline for the first 3 retries, so we can step with a | |||||
// debugger without worrying about deadlines. | |||||
int tries = 0; | |||||
while (tries < 3 || System.currentTimeMillis() < deadline) { | |||||
List<String> names = readTableNames(); | List<String> names = readTableNames(); | ||||
tries++; | |||||
try { | try { | ||||
reloadOnce(names); | reloadOnce(names); | ||||
success = true; | success = true; | ||||
} | } | ||||
if (!success) { | if (!success) { | ||||
// TODO: should reexamine the 'refs' file to see if it was the same | |||||
// if it didn't change, then we must have corruption. If it did, | |||||
// retry. | |||||
throw new LockFailedException(stackPath); | throw new LockFailedException(stackPath); | ||||
} | } | ||||
* | * | ||||
* @param w | * @param w | ||||
* writer to write data to a reftable under construction | * writer to write data to a reftable under construction | ||||
* @return true if the transaction. | |||||
* @return true if the transaction was successful. | |||||
* @throws IOException | * @throws IOException | ||||
* on I/O problems | * on I/O problems | ||||
*/ | */ |
import java.io.IOException; | import java.io.IOException; | ||||
import org.eclipse.jgit.annotations.Nullable; | |||||
import org.eclipse.jgit.lib.ReflogEntry; | import org.eclipse.jgit.lib.ReflogEntry; | ||||
/** | /** | ||||
/** | /** | ||||
* Get current log entry. | * Get current log entry. | ||||
* | * | ||||
* @return current log entry. | |||||
* @return current log entry. Maybe null if we are producing deletions. | |||||
*/ | */ | ||||
@Nullable | |||||
public abstract ReflogEntry getReflogEntry(); | public abstract ReflogEntry getReflogEntry(); | ||||
/** {@inheritDoc} */ | /** {@inheritDoc} */ |