From 9d41d856a7de0e70ef5003686dde889c021b0af8 Mon Sep 17 00:00:00 2001 From: Olivier Bertrand Date: Mon, 5 May 2014 17:36:16 +0200 Subject: [PATCH] - Fix a bug concerning index mapping that caused mapped index files not to be unmapped. This caused a crash instead of reporting an error. This was also fixed. modified: storage/connect/connect.cc storage/connect/ha_connect.cc storage/connect/maputil.cpp storage/connect/table.cpp storage/connect/xindex.cpp storage/connect/xindex.h storage/connect/xtable.h --- storage/connect/connect.cc | 4 +- storage/connect/ha_connect.cc | 11 +++-- storage/connect/maputil.cpp | 11 ++++- storage/connect/table.cpp | 15 ++++-- storage/connect/xindex.cpp | 89 +++++++++++++++-------------------- storage/connect/xindex.h | 7 +-- storage/connect/xtable.h | 3 +- 7 files changed, 70 insertions(+), 70 deletions(-) diff --git a/storage/connect/connect.cc b/storage/connect/connect.cc index 77f23edb79c..32997f53068 100644 --- a/storage/connect/connect.cc +++ b/storage/connect/connect.cc @@ -442,7 +442,7 @@ RCODE CntReadNext(PGLOBAL g, PTDB tdbp) for (PCOL colp= tdbp->GetColumns(); colp; colp= colp->GetNext()) colp->SetKcol(NULL); - ((PTDBASE)tdbp)->SetKindex(NULL); + ((PTDBASE)tdbp)->ResetKindex(g, NULL); } // endif index // Save stack and allocation environment and prepare error return @@ -585,7 +585,7 @@ int CntCloseTable(PGLOBAL g, PTDB tdbp) // Make all the eventual indexes tbxp= (TDBDOX*)tdbp; - tbxp->SetKindex(NULL); + tbxp->ResetKindex(g, NULL); tbxp->To_Key_Col= NULL; rc= tbxp->ResetTableOpt(g, ((PTDBASE)tdbp)->GetDef()->Indexable() == 1); diff --git a/storage/connect/ha_connect.cc b/storage/connect/ha_connect.cc index 7ba5682c01f..974906d6ed5 100644 --- a/storage/connect/ha_connect.cc +++ b/storage/connect/ha_connect.cc @@ -413,9 +413,9 @@ static int connect_init_func(void *p) init_connect_psi_keys(); connect_hton= (handlerton *)p; - connect_hton->state= SHOW_OPTION_YES; - connect_hton->create= connect_create_handler; - connect_hton->flags= HTON_TEMPORARY_NOT_SUPPORTED | HTON_NO_PARTITION; + connect_hton->state= SHOW_OPTION_YES; + connect_hton->create= connect_create_handler; + connect_hton->flags= HTON_TEMPORARY_NOT_SUPPORTED | HTON_NO_PARTITION; connect_hton->table_options= connect_table_option_list; connect_hton->field_options= connect_field_option_list; connect_hton->tablefile_extensions= ha_connect_exts; @@ -2449,7 +2449,7 @@ int ha_connect::index_init(uint idx, bool sorted) } // endif index type if ((rc= rnd_init(0))) - return rc; + DBUG_RETURN(rc); if (locked == 2) { // Indexes are not updated in lock write mode @@ -3816,7 +3816,8 @@ ha_rows ha_connect::records_in_range(uint inx, key_range *min_key, DBUG_ENTER("ha_connect::records_in_range"); if (indexing < 0 || inx != active_index) - index_init(inx, false); + if (index_init(inx, false)) + DBUG_RETURN(HA_POS_ERROR); if (xtrace) htrc("records_in_range: inx=%d indexing=%d\n", inx, indexing); diff --git a/storage/connect/maputil.cpp b/storage/connect/maputil.cpp index b7032f10d2b..7104259ebad 100644 --- a/storage/connect/maputil.cpp +++ b/storage/connect/maputil.cpp @@ -80,7 +80,16 @@ HANDLE CreateFileMap(PGLOBAL g, LPCSTR filename, } // endif hFileMap access = (mode == MODE_READ) ? FILE_MAP_READ : FILE_MAP_WRITE; - mm->memory = MapViewOfFile(hFileMap, access, 0, 0, 0); + + if (!(mm->memory = MapViewOfFile(hFileMap, access, 0, 0, 0))) { + DWORD ler = GetLastError(); + + sprintf(g->Message, "Error %ld in MapViewOfFile %s", + ler, filename); + CloseHandle(hFile); + return INVALID_HANDLE_VALUE; + } // endif memory + // lenH is the high-order word of the file size mm->lenL = GetFileSize(hFile, &mm->lenH); CloseHandle(hFileMap); // Not used anymore diff --git a/storage/connect/table.cpp b/storage/connect/table.cpp index 9749673ad71..325e80945f7 100644 --- a/storage/connect/table.cpp +++ b/storage/connect/table.cpp @@ -304,15 +304,22 @@ int TDBASE::ResetTableOpt(PGLOBAL g, bool dox) } // end of ResetTableOpt /***********************************************************************/ -/* SetKindex: set or reset the index pointer. */ +/* ResetKindex: set or reset the index pointer. */ /***********************************************************************/ -void TDBASE::SetKindex(PKXBASE kxp) +void TDBASE::ResetKindex(PGLOBAL g, PKXBASE kxp) { - if (To_Kindex) + if (To_Kindex) { + int pos = GetRecpos(); // To be reset in Txfp + + for (PCOL colp= Columns; colp; colp= colp->GetNext()) + colp->SetKcol(NULL); + To_Kindex->Close(); // Discard old index + SetRecpos(g, pos); // Ignore return value + } // endif To_Kindex To_Kindex = kxp; - } // end of SetKindex + } // end of ResetKindex /***********************************************************************/ /* SetRecpos: Replace the table at the specified position. */ diff --git a/storage/connect/xindex.cpp b/storage/connect/xindex.cpp index ac4329d8683..21a06c6e992 100755 --- a/storage/connect/xindex.cpp +++ b/storage/connect/xindex.cpp @@ -2131,9 +2131,6 @@ int XINDXS::FastFind(int nk) XLOAD::XLOAD(void) { Hfile = INVALID_HANDLE_VALUE; -#if defined(WIN32) && defined(XMAP) - ViewBase = NULL; -#endif // WIN32 && XMAP NewOff.Val = 0LL; } // end of XLOAD constructor @@ -2147,15 +2144,6 @@ void XLOAD::Close(void) Hfile = INVALID_HANDLE_VALUE; } // endif Hfile -#if defined(WIN32) && defined(XMAP) - if (ViewBase) { - if (!UnmapViewOfFile(ViewBase)) - printf("Error %d closing Viewmap\n", GetLastError()); - - ViewBase = NULL; - } // endif ViewBase -#endif // WIN32 && XMAP - } // end of Close /* --------------------------- XFILE Class --------------------------- */ @@ -2166,9 +2154,9 @@ void XLOAD::Close(void) XFILE::XFILE(void) : XLOAD() { Xfile = NULL; -#if defined(XMAP) && !defined(WIN32) +#if defined(XMAP) Mmp = NULL; -#endif // XMAP && !WIN32 +#endif // XMAP } // end of XFILE constructor /***********************************************************************/ @@ -2193,9 +2181,9 @@ bool XFILE::Open(PGLOBAL g, char *filename, int id, MODE mode) } // endswitch mode if (!(Xfile= global_fopen(g, MSGID_OPEN_ERROR_AND_STRERROR, filename, pmod))) { -#if defined(TRACE) - printf("Open: %s\n", g->Message); -#endif // TRACE + if (trace) + htrc("Open: %s\n", g->Message); + return true; } // endif Xfile @@ -2311,11 +2299,9 @@ void XFILE::Close(void) Xfile = NULL; } // endif Xfile -#if defined(XMAP) && !defined(WIN32) - if (Mmp) { - CloseMemMap(Mmp->memory, Mmp->lenL); - Mmp = NULL; - } // endif Mmp +#if defined(XMAP) + if (Mmp && CloseMemMap(Mmp->memory, Mmp->lenL)) + printf("Error %d closing mapped index\n"); #endif // XMAP } // end of Close @@ -2357,9 +2343,8 @@ bool XHUGE::Open(PGLOBAL g, char *filename, int id, MODE mode) return true; } // endif -#if defined(TRACE) - printf( "Xopen: filename=%s mode=%d\n", filename, mode); -#endif // TRACE + if (trace) + htrc(" Xopen: filename=%s mode=%d\n", filename, mode); #if defined(WIN32) LONG high = 0; @@ -2476,16 +2461,15 @@ bool XHUGE::Open(PGLOBAL g, char *filename, int id, MODE mode) if (Hfile == INVALID_HANDLE_VALUE) { /*rc = errno;*/ -#if defined(TRACE) - printf("Open: %s\n", g->Message); -#endif // TRACE + if (trace) + htrc("Open: %s\n", g->Message); + return true; } // endif Hfile -#if defined(TRACE) - printf(" rc=%d oflag=%p mode=%d handle=%d fn=%s\n", + if (trace) + htrc(" rc=%d oflag=%p mode=%d handle=%d fn=%s\n", rc, oflag, mode, Hfile, filename); -#endif // TRACE if (mode == MODE_INSERT) { /*******************************************************************/ @@ -2588,15 +2572,15 @@ bool XHUGE::Read(PGLOBAL g, void *buf, int n, int size) #else // UNIX ssize_t count = (ssize_t)(n * size); -#if defined(TRACE) - printf("Hfile=%d n=%d size=%d count=%d\n", Hfile, n, size, count); -#endif // TRACE + if (trace) + htrc("Hfile=%d n=%d size=%d count=%d\n", Hfile, n, size, count); if (read(Hfile, buf, count) != count) { sprintf(g->Message, MSG(READ_ERROR), "Index file", strerror(errno)); -#if defined(TRACE) - printf("read error %d\n", errno); -#endif // TRACE + + if (trace) + htrc("read error %d\n", errno); + rc = true; } // endif nbr #endif // UNIX @@ -2854,8 +2838,7 @@ bool KXYCOL::Init(PGLOBAL g, PCOL colp, int n, bool sm, int kln) // Allocate the Value object used when moving items Type = colp->GetResultType(); - if (!(Valp = AllocateValue(g, Type, len, colp->GetScale(), - colp->IsUnsigned()))) + if (!(Valp = AllocateValue(g, Type, len, prec, colp->IsUnsigned()))) return true; Klen = Valp->GetClen(); @@ -2877,10 +2860,11 @@ bool KXYCOL::Init(PGLOBAL g, PCOL colp, int n, bool sm, int kln) // Store this information to avoid sorting when already done if (Asc) -// IsSorted = colp->GetOpt() < 0; +// IsSorted = colp->GetOpt() == 2; IsSorted = false; //SetNulls(colp->IsNullable()); for when null columns will be indexable + Colp = colp; return false; } // end of Init @@ -2891,7 +2875,7 @@ bool KXYCOL::Init(PGLOBAL g, PCOL colp, int n, bool sm, int kln) /***********************************************************************/ BYTE* KXYCOL::MapInit(PGLOBAL g, PCOL colp, int *n, BYTE *m) { - int len = colp->GetLength(), prec = colp->GetPrecision(); + int len = colp->GetLength(), prec = colp->GetScale(); if (n[3] && colp->GetLength() > n[3] && colp->GetResultType() == TYPE_STRING) { @@ -2906,7 +2890,7 @@ BYTE* KXYCOL::MapInit(PGLOBAL g, PCOL colp, int *n, BYTE *m) this, colp, Type, n[0], len, m); // Allocate the Value object used when moving items - Valp = AllocateValue(g, Type, len, prec, false, NULL); + Valp = AllocateValue(g, Type, len, prec, colp->IsUnsigned()); Klen = Valp->GetClen(); if (n[2]) { @@ -2926,7 +2910,7 @@ BYTE* KXYCOL::MapInit(PGLOBAL g, PCOL colp, int *n, BYTE *m) // by blanks (if true) or keep the zero ending char (if false). // Currently we set it to true to be compatible with QRY blocks, // and last one to enable type checking (no conversion). - Kblp = AllocValBlock(g, To_Keys, Type, n[0], len, prec, true, true); + Kblp = AllocValBlock(g, To_Keys, Type, n[0], len, prec, !Prefix, true); if (n[1]) { Koff.Size = n[1] * sizeof(int); @@ -2937,6 +2921,7 @@ BYTE* KXYCOL::MapInit(PGLOBAL g, PCOL colp, int *n, BYTE *m) Ndf = n[0]; //IsSorted = colp->GetOpt() < 0; IsSorted = false; + Colp = colp; return m + Bkeys.Size + Keys.Size + Koff.Size; } // end of MapInit #endif // XMAP @@ -3054,9 +3039,8 @@ int KXYCOL::Compare(int i1, int i2) // Do the actual comparison between values. register int k = Kblp->CompVal(i1, i2); -#ifdef DEBUG2 - htrc("Compare done result=%d\n", k); -#endif + if (trace > 2) + htrc("Compare done result=%d\n", k); return (Asc) ? k : -k; } // end of Compare @@ -3067,13 +3051,14 @@ int KXYCOL::Compare(int i1, int i2) int KXYCOL::CompVal(int i) { // Do the actual comparison between numerical values. -#ifdef DEBUG2 - register int k = (int)Kblp->CompVal(Valp, (int)i); + if (trace > 2) { + register int k = (int)Kblp->CompVal(Valp, (int)i); + + htrc("Compare done result=%d\n", k); + return k; + } else + return Kblp->CompVal(Valp, i); - htrc("Compare done result=%d\n", k); - return k; -#endif - return Kblp->CompVal(Valp, i); } // end of CompVal /***********************************************************************/ diff --git a/storage/connect/xindex.h b/storage/connect/xindex.h index 6ed0416bad5..62430ffa0ad 100644 --- a/storage/connect/xindex.h +++ b/storage/connect/xindex.h @@ -339,9 +339,6 @@ class DllExport XLOAD : public BLOCK { // Members #if defined(WIN32) HANDLE Hfile; // Handle to file or map -#if defined(XMAP) - void *ViewBase; // Mapped view base address -#endif // XMAP #else // UNIX int Hfile; // Descriptor to file or map #endif // UNIX @@ -369,9 +366,9 @@ class DllExport XFILE : public XLOAD { protected: // Members - FILE *Xfile; // Index stream file + FILE *Xfile; // Index stream file #if defined(XMAP) - MMP Mmp; // To mapped index file + MMP Mmp; // Mapped view base address and length #endif // XMAP }; // end of class XFILE diff --git a/storage/connect/xtable.h b/storage/connect/xtable.h index 027e22f5e01..1f937bba6c1 100644 --- a/storage/connect/xtable.h +++ b/storage/connect/xtable.h @@ -142,9 +142,10 @@ class DllExport TDBASE : public TDB { inline PKXBASE GetKindex(void) {return To_Kindex;} inline PCOL GetSetCols(void) {return To_SetCols;} inline void SetSetCols(PCOL colp) {To_SetCols = colp;} + inline void SetKindex(PKXBASE kxp) {To_Kindex = kxp;} // Properties - void SetKindex(PKXBASE kxp); + void ResetKindex(PGLOBAL g, PKXBASE kxp); PCOL Key(int i) {return (To_Key_Col) ? To_Key_Col[i] : NULL;} // Methods