Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Occasional error during database restore #9974

Closed
npomaroli opened this issue Apr 26, 2023 · 3 comments
Closed

Occasional error during database restore #9974

npomaroli opened this issue Apr 26, 2023 · 3 comments
Labels
Milestone

Comments

@npomaroli
Copy link

npomaroli commented Apr 26, 2023

OrientDB Version: >= 3.2.14

Java Version: OpenJDK 11.0.18-1

OS: Any

Expected behavior

Restore of a backup (made with the same OrientDB version) should work without errors.

Actual behavior

There seems to be some sort of race condition between the restore process, which tries to open the database right after restoring the files, and some job, which is scheduled in ViewManager. This sometimes causes the restore process to throw this exception:

com.orientechnologies.orient.core.exception.OStorageException: Storage database is in wrong state MIGRATION and can not be opened.
	DB name="database"
	at com.orientechnologies.orient.core.storage.impl.local.OAbstractPaginatedStorage.open(OAbstractPaginatedStorage.java:362)
	at com.orientechnologies.orient.core.storage.impl.local.OAbstractPaginatedStorage.open(OAbstractPaginatedStorage.java:334)
	at com.orientechnologies.orient.core.storage.disk.OLocalPaginatedStorage.restore(OLocalPaginatedStorage.java:373)
	at com.orientechnologies.orient.core.db.document.ODatabaseDocumentEmbedded.restore(ODatabaseDocumentEmbedded.java:1863)

Steps to reproduce

I created a JUnit test, which reproduces the error, when used with OrientDB >= 3.2.14.

import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;

import org.apache.commons.io.FileUtils;
import org.junit.BeforeClass;
import org.junit.Test;

import com.orientechnologies.orient.core.db.ODatabaseSession;
import com.orientechnologies.orient.core.db.ODatabaseType;
import com.orientechnologies.orient.core.db.OrientDB;

public class BackupRestoreTest {
	public final static int repeat = 100;

	public final static String basePath = "path";

	public final File backupFile = new File(basePath, "backup.zip");

	public final static String dbName = "database";

	public final static String user = "admin";

	public final static String password = "admin";

	@BeforeClass
	public static void clean() throws IOException {
		File baseDir = new File(basePath);
		if (baseDir.isDirectory()) {
			FileUtils.deleteDirectory(baseDir);
		}
	}

	@Test
	public void testBackupRestore() throws IOException {
		System.setProperty("security.createDefaultUsers", "true");

		try (OrientDB db = new OrientDB("plocal:" + basePath, user, password, null)) {
			System.out.println("Creating db");
			db.create(dbName, ODatabaseType.PLOCAL);

			System.out.println("Creating backup");
			backup(db);

			for (int i = 0; i < repeat; i++) {
				System.out.println(String.format("Restoring backup %d/%d", i + 1, repeat));
				restore(db);
			}
		}
	}

	protected void backup(OrientDB db) throws IOException {
		try (ODatabaseSession session = db.open(dbName, user, password)) {
			try (OutputStream out = new FileOutputStream(backupFile)) {
				session.backup(out, null, null, null, 1, 2048);
			}
		}
	}

	protected void restore(OrientDB db) throws IOException {
		try (ODatabaseSession session = db.open(dbName, user, password)) {
			try (InputStream in = new FileInputStream(backupFile)) {
				session.restore(in, null, null, null);
			}
		}
	}
}

This is the pom.xml with the necessary dependencies:

<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd">
	<modelVersion>4.0.0</modelVersion>
	<groupId>com.gentics</groupId>
	<artifactId>test</artifactId>
	<version>0.0.1-SNAPSHOT</version>

	<build>
		<plugins>
			<plugin>
				<groupId>org.apache.maven.plugins</groupId>
				<artifactId>maven-compiler-plugin</artifactId>
				<configuration>
					<verbose>false</verbose>
					<compilerVersion>11</compilerVersion>
					<source>11</source>
					<target>11</target>
				</configuration>
			</plugin>
		</plugins>
	</build>
	<dependencies>
		<dependency>
			<groupId>junit</groupId>
			<artifactId>junit</artifactId>
			<version>4.12</version>
			<scope>test</scope>
		</dependency>
		<dependency>
			<groupId>com.orientechnologies</groupId>
			<artifactId>orientdb-core</artifactId>
			<version>3.2.14</version>
			<scope>test</scope>
		</dependency>
		<dependency>
			<groupId>commons-io</groupId>
			<artifactId>commons-io</artifactId>
			<version>2.11.0</version>
			<scope>test</scope>
		</dependency>
	</dependencies>
</project>

Is there something, that we can change in the restore procedure to overcome this error (e.g. somehow stop that scheduled job from ViewManager)?

@tglman tglman added this to the 3.2.19 milestone May 5, 2023
@tglman tglman added the bug label May 5, 2023
tglman added a commit that referenced this issue May 9, 2023
@tglman
Copy link
Member

tglman commented May 15, 2023

Hi,

This should be fixed in the 3.2.19 release that was shipped last week.

Regards

@npomaroli
Copy link
Author

Hi,
I still can reproduce the exact same error when using OrientDB 3.2.19 with the reproducer above.

@tglman
Copy link
Member

tglman commented Aug 7, 2023

Hi,

This should be finally fixed, I did add a new test following the reproducer, is released in 3.2.20

Regards

@tglman tglman closed this as completed Aug 7, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Development

No branches or pull requests

2 participants