[tarantool-patches] [PATCH v1 17/21] sql: remove SQL_IOERR errcode

imeevma at tarantool.org imeevma at tarantool.org
Sat May 25 13:44:59 MSK 2019


Removing this error code is part of getting rid of the SQL error
system.
---
 src/box/sql/malloc.c   |  2 +-
 src/box/sql/os_unix.c  | 35 +++++++++++++++--------------------
 src/box/sql/sqlInt.h   | 31 +------------------------------
 src/box/sql/vdbeaux.c  | 38 ++------------------------------------
 src/box/sql/vdbesort.c |  1 -
 5 files changed, 19 insertions(+), 88 deletions(-)

diff --git a/src/box/sql/malloc.c b/src/box/sql/malloc.c
index 14b35a7..3c25458 100644
--- a/src/box/sql/malloc.c
+++ b/src/box/sql/malloc.c
@@ -806,7 +806,7 @@ int
 sqlApiExit(sql * db, int rc)
 {
 	assert(db != 0);
-	if (db->mallocFailed || rc == SQL_IOERR_NOMEM) {
+	if (db->mallocFailed) {
 		return apiOomError(db);
 	}
 	return rc & db->errMask;
diff --git a/src/box/sql/os_unix.c b/src/box/sql/os_unix.c
index e2bda51..f0cf4ac 100644
--- a/src/box/sql/os_unix.c
+++ b/src/box/sql/os_unix.c
@@ -396,7 +396,7 @@ findInodeInfo(unixFile * pFile,	/* Unix file with file desc used in the key */
 	rc = fstat(fd, &statbuf);
 	if (rc != 0) {
 		storeLastErrno(pFile, errno);
-		return SQL_IOERR;
+		return -1;
 	}
 
 	memset(&fileId, 0, sizeof(fileId));
@@ -554,9 +554,9 @@ posixUnlock(sql_file * id, int eFileLock, int handleNFSUnlock)
 					/* In theory, the call to unixFileLock() cannot fail because another
 					 * process is holding an incompatible lock. If it does, this
 					 * indicates that the other process is not following the locking
-					 * protocol. If this happens, return SQL_IOERR_RDLOCK.
+					 * protocol. If this happens, return -1.
 					 */
-					rc = SQL_IOERR_RDLOCK;
+					rc = -1;
 					storeLastErrno(pFile, errno);
 					goto end_unlock;
 				}
@@ -570,7 +570,7 @@ posixUnlock(sql_file * id, int eFileLock, int handleNFSUnlock)
 		if (unixFileLock(pFile, &lock) == 0) {
 			pInode->eFileLock = SHARED_LOCK;
 		} else {
-			rc = SQL_IOERR_UNLOCK;
+			rc = -1;
 			storeLastErrno(pFile, errno);
 			goto end_unlock;
 		}
@@ -588,7 +588,7 @@ posixUnlock(sql_file * id, int eFileLock, int handleNFSUnlock)
 			if (unixFileLock(pFile, &lock) == 0) {
 				pInode->eFileLock = NO_LOCK;
 			} else {
-				rc = SQL_IOERR_UNLOCK;
+				rc = -1;
 				storeLastErrno(pFile, errno);
 				pInode->eFileLock = NO_LOCK;
 				pFile->eFileLock = NO_LOCK;
@@ -755,7 +755,7 @@ seekAndRead(unixFile * id, sql_int64 offset, void *pBuf, int cnt)
 
 /*
  * Read data from a file into a buffer.  Return 0 if all
- * bytes were read successfully and SQL_IOERR if anything goes
+ * bytes were read successfully and -1 if anything goes
  * wrong.
  */
 static int
@@ -792,12 +792,12 @@ unixRead(sql_file * id, void *pBuf, int amt, sql_int64 offset)
 		return 0;
 	} else if (got < 0) {
 		/* lastErrno set by seekAndRead */
-		return SQL_IOERR_READ;
+		return -1;
 	} else {
 		storeLastErrno(pFile, 0);	/* not a system error */
 		/* Unread parts of the buffer must be zero-filled */
 		memset(&((char *)pBuf)[got], 0, amt - got);
-		return SQL_IOERR_SHORT_READ;
+		return -1;
 	}
 }
 
@@ -871,7 +871,7 @@ unixWrite(sql_file * id, const void *pBuf, int amt, sql_int64 offset)
 	if (amt > wrote) {
 		if (wrote < 0 && pFile->lastErrno != ENOSPC) {
 			/* lastErrno set by seekAndWrite */
-			return SQL_IOERR_WRITE;
+			return -1;
 		} else {
 			storeLastErrno(pFile, 0);	/* not a system error */
 			return -1;
@@ -941,7 +941,7 @@ fcntlSizeHint(unixFile * pFile, i64 nByte)
 		struct stat buf;	/* Used to hold return values of fstat() */
 
 		if (fstat(pFile->h, &buf))
-			return SQL_IOERR_FSTAT;
+			return -1;
 
 		nSize =
 		    ((nByte + pFile->szChunk -
@@ -960,7 +960,7 @@ fcntlSizeHint(unixFile * pFile, i64 nByte)
 					iWrite = nSize - 1;
 				nWrite = seekAndWrite(pFile, iWrite, "", 1);
 				if (nWrite != 1)
-					return SQL_IOERR_WRITE;
+					return -1;
 			}
 		}
 	}
@@ -1167,7 +1167,7 @@ unixMapfile(unixFile * pFd, i64 nMap)
 	if (nMap < 0) {
 		struct stat statbuf;	/* Low-level file information */
 		if (fstat(pFd->h, &statbuf))
-			return SQL_IOERR_FSTAT;
+			return -1;
 		nMap = statbuf.st_size;
 	}
 	if (nMap > pFd->mmapSizeMax) {
@@ -1472,7 +1472,7 @@ unixGetTempname(int nBuf, char *zBuf)
 
 	zDir = unixTempFileDir();
 	if (zDir == 0)
-		return SQL_IOERR_GETTEMPPATH;
+		return -1;
 	do {
 		u64 r;
 		sql_randomness(sizeof(r), &r);
@@ -1559,7 +1559,7 @@ getFileMode(const char *zFile,	/* File name */
 		*pUid = sStat.st_uid;
 		*pGid = sStat.st_gid;
 	} else {
-		rc = SQL_IOERR_FSTAT;
+		rc = -1;
 	}
 	return rc;
 }
@@ -1816,12 +1816,7 @@ unixDelete(sql_vfs * NotUsed,	/* VFS containing this as the xDelete method */
 	int rc = 0;
 	UNUSED_PARAMETER(NotUsed);
 	if (unlink(zPath) == (-1)) {
-		if (errno == ENOENT) {
-			rc = SQL_IOERR_DELETE_NOENT;
-		} else {
-			rc = -1;
-		}
-		return rc;
+		return -1;
 	}
 #ifndef SQL_DISABLE_DIRSYNC
 	if ((dirSync & 1) != 0) {
diff --git a/src/box/sql/sqlInt.h b/src/box/sql/sqlInt.h
index a76b4e3..76ac057 100644
--- a/src/box/sql/sqlInt.h
+++ b/src/box/sql/sqlInt.h
@@ -356,10 +356,8 @@ struct sql_vfs {
 #define SQL_LIMIT_WORKER_THREADS           10
 
 enum sql_ret_code {
-	/** Some kind of disk I/O error occurred. */
-	SQL_IOERR = 3,
 	/** Abort due to constraint violation. */
-	SQL_TARANTOOL_ERROR,
+	SQL_TARANTOOL_ERROR = 4,
 	/** sql_step() has another row ready. */
 	SQL_ROW,
 	/** sql_step() has finished executing. */
@@ -561,33 +559,6 @@ sql_exec(sql *,	/* An open database */
 	     void *,	/* 1st argument to callback */
 	     char **errmsg	/* Error msg written here */
 	);
-#define SQL_IOERR_READ              (SQL_IOERR | (1<<8))
-#define SQL_IOERR_SHORT_READ        (SQL_IOERR | (2<<8))
-#define SQL_IOERR_WRITE             (SQL_IOERR | (3<<8))
-#define SQL_IOERR_FSYNC             (SQL_IOERR | (4<<8))
-#define SQL_IOERR_DIR_FSYNC         (SQL_IOERR | (5<<8))
-#define SQL_IOERR_TRUNCATE          (SQL_IOERR | (6<<8))
-#define SQL_IOERR_FSTAT             (SQL_IOERR | (7<<8))
-#define SQL_IOERR_UNLOCK            (SQL_IOERR | (8<<8))
-#define SQL_IOERR_RDLOCK            (SQL_IOERR | (9<<8))
-#define SQL_IOERR_DELETE            (SQL_IOERR | (10<<8))
-#define SQL_IOERR_BLOCKED           (SQL_IOERR | (11<<8))
-#define SQL_IOERR_NOMEM             (SQL_IOERR | (12<<8))
-#define SQL_IOERR_ACCESS            (SQL_IOERR | (13<<8))
-#define SQL_IOERR_CHECKRESERVEDLOCK (SQL_IOERR | (14<<8))
-#define SQL_IOERR_LOCK              (SQL_IOERR | (15<<8))
-#define SQL_IOERR_CLOSE             (SQL_IOERR | (16<<8))
-#define SQL_IOERR_DIR_CLOSE         (SQL_IOERR | (17<<8))
-#define SQL_IOERR_SHMOPEN           (SQL_IOERR | (18<<8))
-#define SQL_IOERR_SHMSIZE           (SQL_IOERR | (19<<8))
-#define SQL_IOERR_SHMLOCK           (SQL_IOERR | (20<<8))
-#define SQL_IOERR_SHMMAP            (SQL_IOERR | (21<<8))
-#define SQL_IOERR_SEEK              (SQL_IOERR | (22<<8))
-#define SQL_IOERR_DELETE_NOENT      (SQL_IOERR | (23<<8))
-#define SQL_IOERR_MMAP              (SQL_IOERR | (24<<8))
-#define SQL_IOERR_GETTEMPPATH       (SQL_IOERR | (25<<8))
-#define SQL_IOERR_CONVPATH          (SQL_IOERR | (26<<8))
-#define SQL_IOERR_VNODE             (SQL_IOERR | (27<<8))
 
 /**
  * Subtype of a main type. Allows to do some subtype specific
diff --git a/src/box/sql/vdbeaux.c b/src/box/sql/vdbeaux.c
index 7408b9f..8e2ca35 100644
--- a/src/box/sql/vdbeaux.c
+++ b/src/box/sql/vdbeaux.c
@@ -2055,7 +2055,7 @@ checkActiveVdbeCnt(sql * db)
  * transaction is rolled back. If eOp is SAVEPOINT_RELEASE, then the
  * statement transaction is committed.
  *
- * If an IO error occurs, an SQL_IOERR_XXX error code is returned.
+ * If an IO error occurs, -1 is returned.
  * Otherwise 0.
  */
 int
@@ -2161,14 +2161,6 @@ sqlVdbeHalt(Vdbe * p)
 	/* This function contains the logic that determines if a statement or
 	 * transaction will be committed or rolled back as a result of the
 	 * execution of this virtual machine.
-	 *
-	 * If any of the following errors occur:
-	 *
-	 *     SQL_IOERR
-	 *
-	 * Then the internal cache might have been left in an inconsistent
-	 * state.  We need to rollback the statement transaction, if there is
-	 * one, or the complete transaction if there is no statement transaction.
 	 */
 
 	if (db->mallocFailed) {
@@ -2184,32 +2176,7 @@ sqlVdbeHalt(Vdbe * p)
 	 * SQL statement does not read or write a database file.
 	 */
 	if (p->pc >= 0) {
-		int mrc;	/* Primary error code from p->rc */
 		int eStatementOp = 0;
-		int isSpecialError;	/* Set to true if a 'special' error */
-
-		/* Check for one of the special errors */
-		mrc = p->rc & 0xff;
-		isSpecialError = mrc == SQL_IOERR;
-		if (isSpecialError) {
-			/* At least a savepoint transaction must be rolled back
-			 * to restore the database to a consistent state.
-			 *
-			 * Even if the statement is read-only, it is important to perform
-			 * a statement or transaction rollback operation. If the error
-			 * occurred while writing to the journal, sub-journal or database
-			 * file as part of an effort to free up cache space (see function
-			 * pagerStress() in pager.c), the rollback is required to restore
-			 * the pager to a consistent state.
-			 * We are forced to roll back the active transaction. Before doing
-			 * so, abort any other statements this handle currently has active.
-			 */
-			box_txn_rollback();
-			closeCursorsAndFree(p);
-			sqlRollbackAll(p);
-			sqlCloseSavepoints(p);
-			p->nChange = 0;
-		}
 
 		/* Check for immediate foreign key violations. */
 		if (p->rc == 0) {
@@ -2224,8 +2191,7 @@ sqlVdbeHalt(Vdbe * p)
 		 */
 		if (p->auto_commit) {
 			if (p->rc == 0
-			    || (p->errorAction == ON_CONFLICT_ACTION_FAIL
-				&& !isSpecialError)) {
+			    || (p->errorAction == ON_CONFLICT_ACTION_FAIL)) {
 				rc = sqlVdbeCheckFk(p, 1);
 				if (rc != 0) {
 					/* Close all opened cursors if
diff --git a/src/box/sql/vdbesort.c b/src/box/sql/vdbesort.c
index 3ff6807..7caf13b 100644
--- a/src/box/sql/vdbesort.c
+++ b/src/box/sql/vdbesort.c
@@ -542,7 +542,6 @@ vdbePmaReadBlob(PmaReader * p,	/* PmaReader from which to take the blob */
 
 		/* Readr data from the file. Return early if an error occurs. */
 		rc = sqlOsRead(p->pFd, p->aBuffer, nRead, p->iReadOff);
-		assert(rc != SQL_IOERR_SHORT_READ);
 		if (rc != 0)
 			return rc;
 	}
-- 
2.7.4





More information about the Tarantool-patches mailing list