ING_DB
This commit is contained in:
parent
3f48ff9b7f
commit
886d9ee47b
|
|
@ -0,0 +1,101 @@
|
|||
# include "AA_liba.h"
|
||||
|
||||
AAcloser(desc, rel)
|
||||
register DESCXX **desc;
|
||||
char *rel;
|
||||
{
|
||||
register DESCXX *d;
|
||||
register DESCXX *next;
|
||||
|
||||
errno = 0;
|
||||
|
||||
if (!AA_DESC)
|
||||
AAerror(111, "close");
|
||||
|
||||
if (!(d = *desc))
|
||||
AAerror(106, rel);
|
||||
|
||||
do
|
||||
{
|
||||
d->xx_desc.relopn = RELWOPEN(d->xx_desc.relfp);
|
||||
|
||||
# ifdef AMX_TRACE
|
||||
AAtTfp(2, 0,
|
||||
# ifdef MSDOS
|
||||
"close\t\t`%.10s'\n",
|
||||
# else
|
||||
"close\t\t`%.14s'\n",
|
||||
# endif
|
||||
d->xx_desc.reldum.relid);
|
||||
# endif
|
||||
|
||||
|
||||
# ifndef MSDOS
|
||||
if (!(AA_NOLOCKS
|
||||
|| bitset(S_CATALOG, d->xx_desc.reldum.relstat)
|
||||
|| bitset(S_INDEX, d->xx_desc.reldum.relstat)))
|
||||
AAunlus(d->xx_desc.reltid);
|
||||
# endif
|
||||
if (AA = AArelclose(d))
|
||||
AAerror(1, rel);
|
||||
|
||||
for (next = AA_DESC; next->xx_next != d; next = next->xx_next)
|
||||
continue;
|
||||
next->xx_next = d->xx_next;
|
||||
free(d);
|
||||
|
||||
} while (d = d->xx_index);
|
||||
|
||||
d = *desc;
|
||||
*desc = (DESCXX *) 0;
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
** AAnoclose - update system catalogs for a relation
|
||||
** DESCRIPTION
|
||||
**
|
||||
** function values:
|
||||
** <0 fatal error
|
||||
** 0 success
|
||||
** 1 relation was not open
|
||||
*/
|
||||
AAnoclose(d)
|
||||
register DESCXX *d;
|
||||
{
|
||||
register int i;
|
||||
struct relation rel;
|
||||
|
||||
# ifdef AMX_TRACE
|
||||
AAtTfp(13, 0,
|
||||
# ifdef MSDOS
|
||||
"flush\t\t`%.10s' (%ld)\n",
|
||||
# else
|
||||
"flush\t\t`%.14s' (%ld)\n",
|
||||
# endif
|
||||
d->xx_desc.reldum.relid, d->xx_desc.reladds);
|
||||
# endif
|
||||
|
||||
/* flush all pages associated with relation */
|
||||
/* reset all the buffers so they can't be reused */
|
||||
i = AAam_flush_rel(d, 1);
|
||||
|
||||
/* check to see if number of tuples has changed */
|
||||
if (d->xx_desc.reladds && !(i = AAgetpage(AA_rel, &d->xx_desc.reltid)))
|
||||
{
|
||||
/* yes, update the system catalogs */
|
||||
/* get tuple from catalog AA_REL */
|
||||
AAget_tuple(AA_rel, &d->xx_desc.reltid, &rel);
|
||||
|
||||
/* update the reltups field */
|
||||
rel.reltups += d->xx_desc.reladds;
|
||||
d->xx_desc.reldum.reltups = rel.reltups;
|
||||
|
||||
/* put the tuple back */
|
||||
AAput_tuple(&d->xx_desc.reltid, &rel, AA_rel->reldum.relwid);
|
||||
i = AAresetacc(AAcc_head);
|
||||
d->xx_desc.reladds = 0;
|
||||
}
|
||||
|
||||
return (i);
|
||||
}
|
||||
|
|
@ -0,0 +1,176 @@
|
|||
# include "AA_liba.h"
|
||||
|
||||
# define DRIVER_LOCKED -4
|
||||
|
||||
static int AA_2_TA;
|
||||
|
||||
AAlock(d, rel, mod)
|
||||
register DESCXX *d;
|
||||
char *rel;
|
||||
register int mod;
|
||||
{
|
||||
register DESCXX *i;
|
||||
|
||||
errno = 0;
|
||||
|
||||
if (!AA_DESC)
|
||||
AAerror(111, "use");
|
||||
|
||||
# ifdef AMX_TRACE
|
||||
AAtTfp(14, 0,
|
||||
# ifdef MSDOS
|
||||
"use\t\t`%.10s' (%d) mod 0%o\n",
|
||||
# else
|
||||
"use\t\t`%.14s' (%d) mod 0%o\n",
|
||||
# endif
|
||||
rel, d->xx_locks, mod);
|
||||
# endif
|
||||
|
||||
if (!d)
|
||||
AAerror(106, rel);
|
||||
|
||||
if (AA_NOLOCKS)
|
||||
return;
|
||||
|
||||
if (AA_LOCKS)
|
||||
AAerror(107, "TA-begin");
|
||||
|
||||
if (mod < 0)
|
||||
{
|
||||
if (AA_2_TA)
|
||||
goto concur;
|
||||
mod = -mod;
|
||||
AA_2_TA++;
|
||||
}
|
||||
else if (!AA_2_TA)
|
||||
{
|
||||
concur:
|
||||
AAerror(107, "second TA");
|
||||
}
|
||||
|
||||
for (i = d; i = i->xx_index; )
|
||||
AArel_lock(i, mod);
|
||||
AArel_lock(d, mod);
|
||||
}
|
||||
|
||||
|
||||
static AArel_lock(d, mod)
|
||||
register DESCXX *d;
|
||||
register int mod;
|
||||
{
|
||||
register int i;
|
||||
|
||||
# ifndef MSDOS
|
||||
if (ctoi(d->xx_desc.reldum.relindxd) == SECINDEX)
|
||||
mod &= ~M_TE;
|
||||
# endif
|
||||
|
||||
# ifdef AMX_TRACE
|
||||
AAtTfp(31, 0,
|
||||
# ifdef MSDOS
|
||||
"lock\t\t`%.10s' (%d) mod 0%o\n",
|
||||
# else
|
||||
"lock\t\t`%.14s' (%d) mod 0%o\n",
|
||||
# endif
|
||||
d->xx_desc.reldum.relid, d->xx_locks, mod);
|
||||
# endif
|
||||
AA = errno = 0;
|
||||
|
||||
if (d->xx_ta)
|
||||
AAerror(17, d->xx_desc.reldum.relid);
|
||||
|
||||
d->xx_refresh = 0;
|
||||
|
||||
if ((d->xx_excl = mod) & M_EXCL)
|
||||
{
|
||||
/* restore relation of descriptor d to read/write mode */
|
||||
d->xx_desc.relopn = RELWOPEN(d->xx_desc.relfp);
|
||||
}
|
||||
|
||||
if (AA_TA)
|
||||
AA_TE->xx_ta = d;
|
||||
else
|
||||
AA_TA = d;
|
||||
AA_TE = d;
|
||||
|
||||
restart:
|
||||
errno = 0;
|
||||
for ( ; d; d = d->xx_ta)
|
||||
{
|
||||
# ifdef AMX_TRACE
|
||||
AAtTfp(31, 1,
|
||||
# ifdef MSDOS
|
||||
".... %s (%d)\t`%.10s'\n",
|
||||
# else
|
||||
".... %s (%d)\t`%.14s'\n",
|
||||
# endif
|
||||
(d == AA_TA)? "slp": "rtn", d->xx_excl, d->xx_desc.reldum.relid);
|
||||
# endif
|
||||
if (AAsetrll((d == AA_TA)? A_SLP: A_RTN, d->xx_desc.reltid, d->xx_excl) < 0)
|
||||
{
|
||||
/* the lock request fails */
|
||||
AAunlock(i = errno == DRIVER_LOCKED);
|
||||
if (i)
|
||||
AAerror(109, "aborted");
|
||||
d = AA_TA;
|
||||
goto restart;
|
||||
}
|
||||
d->xx_locks++;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
AAunlock(really)
|
||||
register int really;
|
||||
{
|
||||
register DESCXX *next;
|
||||
register DESCXX *d;
|
||||
|
||||
# ifdef AMX_TRACE
|
||||
AAtTfp(15, 0, "commit\t\t(%d)\n", really);
|
||||
# endif
|
||||
|
||||
if (!AA_DESC)
|
||||
AAerror(111, "commit");
|
||||
|
||||
if (AA_NOLOCKS)
|
||||
return;
|
||||
|
||||
if (!(d = AA_TA))
|
||||
AAerror(107, "TA-end");
|
||||
|
||||
for ( ; d; d = next)
|
||||
{
|
||||
# ifdef AMX_TRACE
|
||||
AAtTfp(15, 1,
|
||||
# ifdef MSDOS
|
||||
"unlock\t\t`%.10s' (%d)\n",
|
||||
# else
|
||||
"unlock\t\t`%.14s' (%d)\n",
|
||||
# endif
|
||||
d->xx_desc.reldum.relid, d->xx_locks);
|
||||
# endif
|
||||
next = d->xx_ta;
|
||||
if (really)
|
||||
{
|
||||
d->xx_excl = 0;
|
||||
d->xx_ta = (DESCXX *) 0;
|
||||
AAnoclose(d);
|
||||
/* make believe relation is read only */
|
||||
/* for concurrency that means, */
|
||||
/* readed pages are not locked */
|
||||
if (!bitset(S_CATALOG, d->xx_desc.reldum.relstat))
|
||||
d->xx_desc.relopn = RELROPEN(d->xx_desc.relfp);
|
||||
}
|
||||
if ((AA = d->xx_locks) && AAunlrl(d->xx_desc.reltid) < 0)
|
||||
AAerror(18, d->xx_desc.reldum.relid);
|
||||
d->xx_locks = 0;
|
||||
}
|
||||
if (really)
|
||||
{
|
||||
sync();
|
||||
AA_TE = AA_TA = (DESCXX *) 0;
|
||||
AA_2_TA = 0;
|
||||
AAdaemon = 0;
|
||||
}
|
||||
}
|
||||
Loading…
Reference in New Issue