Annotation of 42BSD/ingres/source/dbu/destroy.c, revision 1.1.1.1

1.1       root        1: # include      <pv.h>
                      2: # include      <ingres.h>
                      3: # include      <aux.h>
                      4: # include      <catalog.h>
                      5: # include      <func.h>
                      6: # include      <sccs.h>
                      7: 
                      8: SCCSID(@(#)destroy.c   7.1     2/5/81)
                      9: 
                     10: extern short   tTdbu[];
                     11: extern int     destroy();
                     12: extern         int     null_fn();
                     13: 
                     14: struct fn_def DstroyFn =
                     15: {
                     16:        "DESTROY",
                     17:        destroy,
                     18:        null_fn,
                     19:        null_fn,
                     20:        NULL,
                     21:        0,
                     22:        tTdbu,
                     23:        100,
                     24:        'Z',
                     25:        0
                     26: };
                     27: 
                     28: 
                     29: /*
                     30: **  DESTROY RELATION
                     31: **
                     32: **     The relations in pv are destroyed.  This involves three steps:
                     33: **     1 - remove tuple from relation relation
                     34: **     2 - remove tuples from attribute relation
                     35: **     3 - unlink physical file
                     36: **
                     37: **     If the relation is a secondary index, the entry is removed
                     38: **     from the index relation, and the primary relation is set to
                     39: **     be "not indexed" (unless there is another index on it).
                     40: **
                     41: **     If the relation has an index, all its indexes are also
                     42: **     destroyed.
                     43: **
                     44: **     If any errors occured while destroying the relations,
                     45: **     then the last error number is returned, otherwise
                     46: **     0 is returned.
                     47: **
                     48: **     If any query modification was defined on the relation,
                     49: **     the qrymod catalogues are updated.
                     50: **
                     51: **     Trace Flags:
                     52: **             32
                     53: */
                     54: 
                     55: destroy(pc, pv)
                     56: int    pc;
                     57: PARM   *pv;
                     58: {
                     59:        register int    i, ret;
                     60:        register char   *name;
                     61: 
                     62:        opencatalog("relation", 2);
                     63:        opencatalog("attribute", 2);
                     64: 
                     65:        for (ret = 0; pc-- > 0; )
                     66:        {
                     67:                name = ((pv++)->pv_val).pv_str;
                     68:                if (i = des(name))
                     69:                        ret = i;
                     70:        }
                     71:        return (ret);
                     72: }
                     73: 
                     74: 
                     75: des(name)
                     76: char   *name;
                     77: {
                     78:        register int    i;
                     79:        register char   *relname;
                     80:        struct tup_id   tid;
                     81:        char            newrelname[MAXNAME + 3];
                     82:        extern DESC     Reldes, Attdes, Inddes, Treedes;
                     83:        struct relation relt, relk;
                     84: 
                     85:        relname = name;
                     86: #      ifdef xZTR1
                     87:        tTfp(32, -1, "destroy: %s\n", relname);
                     88: #      endif
                     89: 
                     90:        newrelname[MAXNAME + 2] = 0;
                     91: 
                     92:        /* get the tuple from relation relation */
                     93:        setkey(&Reldes, &relk, relname, RELID);
                     94:        setkey(&Reldes, &relk, Usercode, RELOWNER);
                     95:        if ((i = getequal(&Reldes, &relk, &relt, &tid)) != 0)
                     96:        {
                     97:                if (i < 0)
                     98:                        syserr("DESTROY: geteq(rel/%s) %d", relname, i);
                     99:                return (nferror(5202, relname, 0));     /* nonexistant relation */
                    100:        }
                    101: 
                    102:        /* don't allow a system relation to be destroyed */
                    103:        if (relt.relstat & S_CATALOG)
                    104:                return (nferror(5201, relname, 0));     /* attempt to destroy system catalog */
                    105: 
                    106:        if ((i = delete(&Reldes, &tid)) != 0)
                    107:                syserr("DESTROY: delete(rel) %d", i);
                    108: 
                    109:        /*
                    110:        ** for concurrency reasons, flush the relation-relation page
                    111:        ** where the tuple was just deleted. This will prevent anyone
                    112:        ** from being able to "openr" the relation while it is being
                    113:        ** destroyed. It also allows recovery to finish the destroy
                    114:        ** it the system crashes during this destroy.
                    115:        */
                    116:        if (i = flush_rel(&Reldes, FALSE))
                    117:                syserr("destroy:flush rel %d", i);
                    118: 
                    119:        purgetup(&Attdes, relt.relid, ATTRELID, relt.relowner, ATTOWNER, 0);
                    120: 
                    121:        /*
                    122:        **      If this is a user relation, then additional processing
                    123:        **      might be needed to clean up indicies, protection constraints
                    124:        **      etc.
                    125:        */
                    126:        if ((relt.relstat & S_CATALOG) == 0)
                    127:                userdestroy(&relt);
                    128: 
                    129:        if ((relt.relstat & S_VIEW) == 0)
                    130:        {
                    131:                ingresname(relname, Usercode, newrelname);
                    132:                if (unlink(newrelname) < 0)
                    133:                        syserr("destroy: unlink(%.14s)", newrelname);
                    134:        }
                    135:        return (0);
                    136: 
                    137: }

unix.superglobalmegacorp.com

This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.