*** log/log_register.c.orig Sun Sep 27 10:40:32 1998 --- log/log_register.c Fri Jan 15 10:35:52 1999 *************** *** 36,52 **** { DBT fid_dbt, r_name; DB_LSN r_unused; ! FNAME *fnp; size_t len; ! u_int32_t fid; int inserted, ret; char *fullname; void *namep; - fid = 0; inserted = 0; fullname = NULL; ! fnp = namep = NULL; LOG_PANIC_CHECK(dblp); --- 36,51 ---- { DBT fid_dbt, r_name; DB_LSN r_unused; ! FNAME *fnp, *reuse_fnp; size_t len; ! u_int32_t maxid; int inserted, ret; char *fullname; void *namep; inserted = 0; fullname = NULL; ! fnp = namep = reuse_fnp = NULL; LOG_PANIC_CHECK(dblp); *************** *** 65,88 **** /* * See if we've already got this file in the log, finding the ! * next-to-lowest file id currently in use as we do it. */ ! for (fid = 1, fnp = SH_TAILQ_FIRST(&dblp->lp->fq, __fname); fnp != NULL; fnp = SH_TAILQ_NEXT(fnp, q, __fname)) { ! if (fid <= fnp->id) ! fid = fnp->id + 1; if (!memcmp(dbp->fileid, fnp->ufid, DB_FILE_ID_LEN)) { ++fnp->ref; - fid = fnp->id; goto found; } } ! /* Allocate a new file name structure. */ ! if ((ret = __db_shalloc(dblp->addr, sizeof(FNAME), 0, &fnp)) != 0) goto err; fnp->ref = 1; - fnp->id = fid; fnp->s_type = type; memcpy(fnp->ufid, dbp->fileid, DB_FILE_ID_LEN); --- 64,98 ---- /* * See if we've already got this file in the log, finding the ! * (maximum+1) in-use file id and some available file id (if we ! * find an available fid, we'll use it, else we'll have to allocate ! * one after the maximum that we found). */ ! for (maxid = 0, fnp = SH_TAILQ_FIRST(&dblp->lp->fq, __fname); fnp != NULL; fnp = SH_TAILQ_NEXT(fnp, q, __fname)) { ! if (fnp->ref == 0 && reuse_fnp == NULL) { ! /* Entry is not in use. */ ! reuse_fnp = fnp; ! continue; ! } if (!memcmp(dbp->fileid, fnp->ufid, DB_FILE_ID_LEN)) { ++fnp->ref; goto found; } + if (maxid <= fnp->id) + maxid = fnp->id + 1; } ! /* Fill in fnp structure. */ ! ! if (reuse_fnp != NULL) /* Reuse existing one. */ ! fnp = reuse_fnp; ! else if ((ret = __db_shalloc(dblp->addr, sizeof(FNAME), 0, &fnp)) != 0) goto err; + else /* Allocate a new one. */ + fnp->id = maxid; + fnp->ref = 1; fnp->s_type = type; memcpy(fnp->ufid, dbp->fileid, DB_FILE_ID_LEN); *************** *** 92,98 **** fnp->name_off = R_OFFSET(dblp, namep); memcpy(namep, name, len); ! SH_TAILQ_INSERT_HEAD(&dblp->lp->fq, fnp, q, __fname); inserted = 1; found: /* Log the registry. */ --- 102,110 ---- fnp->name_off = R_OFFSET(dblp, namep); memcpy(namep, name, len); ! /* Only do the insert if we allocated a new fnp. */ ! if (reuse_fnp == NULL) ! SH_TAILQ_INSERT_HEAD(&dblp->lp->fq, fnp, q, __fname); inserted = 1; found: /* Log the registry. */ *************** *** 103,111 **** fid_dbt.data = dbp->fileid; fid_dbt.size = DB_FILE_ID_LEN; if ((ret = __log_register_log(dblp, NULL, &r_unused, ! 0, LOG_OPEN, &r_name, &fid_dbt, fid, type)) != 0) goto err; ! if ((ret = __log_add_logid(dblp, dbp, fid)) != 0) goto err; } --- 115,123 ---- fid_dbt.data = dbp->fileid; fid_dbt.size = DB_FILE_ID_LEN; if ((ret = __log_register_log(dblp, NULL, &r_unused, ! 0, LOG_OPEN, &r_name, &fid_dbt, fnp->id, type)) != 0) goto err; ! if ((ret = __log_add_logid(dblp, dbp, fnp->id)) != 0) goto err; } *************** *** 122,134 **** __db_shalloc_free(dblp->addr, fnp); } UNLOCK_LOGREGION(dblp); if (fullname != NULL) __os_freestr(fullname); - if (idp != NULL) - *idp = fid; return (ret); } --- 134,146 ---- __db_shalloc_free(dblp->addr, fnp); } + if (idp != NULL) + *idp = fnp->id; UNLOCK_LOGREGION(dblp); if (fullname != NULL) __os_freestr(fullname); return (ret); } *************** *** 177,191 **** /* * If more than 1 reference, just decrement the reference and return. ! * Otherwise, free the unique file information, name and structure. */ ! if (fnp->ref > 1) ! --fnp->ref; ! else { __db_shalloc_free(dblp->addr, R_ADDR(dblp, fnp->name_off)); - SH_TAILQ_REMOVE(&dblp->lp->fq, fnp, q, __fname); - __db_shalloc_free(dblp->addr, fnp); - } /* * Remove from the process local table. If this operation is taking --- 189,199 ---- /* * If more than 1 reference, just decrement the reference and return. ! * Otherwise, free the name. */ ! --fnp->ref; ! if (fnp->ref == 0) __db_shalloc_free(dblp->addr, R_ADDR(dblp, fnp->name_off)); /* * Remove from the process local table. If this operation is taking