Annotation of 42BSD/ingres/source/dbu/secupdate.c, revision 1.1

1.1     ! root        1: # include      <ingres.h>
        !             2: # include      <aux.h>
        !             3: # include      <catalog.h>
        !             4: # include      <symbol.h>
        !             5: # include      <access.h>
        !             6: # include      <batch.h>
        !             7: # include      <sccs.h>
        !             8: 
        !             9: SCCSID(@(#)secupdate.c 7.1     2/5/81)
        !            10: 
        !            11: secupdate(r)
        !            12: register DESC  *r;
        !            13: {
        !            14:        register char   *p;
        !            15:        register int    i;
        !            16:        int             j, domcnt, mode, dom;
        !            17:        long            tupcnt;
        !            18:        long            oldtid, newtid;
        !            19:        long            lotid, hitid, uptid;
        !            20:        char            oldtup[MAXTUP], newtup[MAXTUP];
        !            21:        char            oldkey[MAXTUP], newkey[MAXTUP];
        !            22:        char            dumtup[MAXTUP];
        !            23:        struct index    itup;
        !            24:        DESC            si_desc;
        !            25:        extern DESC     Inddes;
        !            26:        struct key_pt
        !            27:        {
        !            28:                char    *pt_old;
        !            29:                char    *pt_new;
        !            30:        };
        !            31:        struct key_pt   keys[MAXKEYS+1];
        !            32: 
        !            33:        mode = Batchhd.mode_up;
        !            34:        Batch_dirty = FALSE;
        !            35: #      ifdef xZTR1
        !            36:        if (tTf(49, -1))
        !            37:                printf("SECUPDATE\n");
        !            38: #      endif
        !            39:        opencatalog("indexes", 0);
        !            40:        setkey(&Inddes, &itup, r->reldum.relid, IRELIDP);
        !            41:        setkey(&Inddes, &itup, r->reldum.relowner, IOWNERP);
        !            42:        if (i = find(&Inddes, EXACTKEY, &lotid, &hitid, &itup))
        !            43:                syserr("secupdate:find indexes %d", i);
        !            44: 
        !            45:        /* update each secondary index */
        !            46:        while(!(i = get(&Inddes, &lotid, &hitid, &itup, TRUE)))
        !            47:        {
        !            48:                /* check if the index is on the right relation */
        !            49: #              ifdef xZTR1
        !            50:                if (tTf(49, 7))
        !            51:                        printup(&Inddes, &itup);
        !            52: #              endif
        !            53:                if (!bequal(itup.irelidp, r->reldum.relid, MAXNAME) ||
        !            54:                        !bequal(itup.iownerp, r->reldum.relowner, 2))
        !            55:                        continue;
        !            56: 
        !            57:                if (i = openr(&si_desc, 1, itup.irelidi))
        !            58:                        syserr("secupdate:can't openr %.12s %d", itup.irelidi, i);
        !            59:                /* reposition batch file to the beginning. */
        !            60:                if ((i = lseek(Batch_fp, 0L, 0)) < 0)
        !            61:                        syserr("secupdate:seek %d %d", i, Batch_fp);
        !            62:                Batch_cnt = BATCHSIZE;
        !            63:                getbatch(&Batchhd, sizeof Batchhd);     /* reread header */
        !            64: 
        !            65:                /* set up the key structure */
        !            66:                p = itup.idom;
        !            67:                for (domcnt = 0; domcnt < MAXKEYS; domcnt++)
        !            68:                {
        !            69:                        if ((dom = *p++) == 0)
        !            70:                                break;  /* no more key domains */
        !            71: #                      ifdef xZTR1
        !            72:                        if (tTf(49, 15))
        !            73:                                
        !            74:                                printf("dom %d,tupo_off %d\n", dom, Batchhd.si[dom].tupo_off);
        !            75: #                      endif
        !            76:                        keys[domcnt].pt_old = &oldtup[Batchhd.si[dom].tupo_off];
        !            77:                        keys[domcnt].pt_new = &newtup[r->reloff[dom]];
        !            78:                }
        !            79: 
        !            80:                /* the last domain is the "tidp" field */
        !            81:                keys[domcnt].pt_old = (char *) &oldtid;
        !            82:                keys[domcnt].pt_new = (char *) &newtid;
        !            83: 
        !            84:                /*
        !            85:                ** Start reading the batch file and updating
        !            86:                ** the secondary indexes.
        !            87:                */
        !            88:                tupcnt = Batchhd.num_updts;
        !            89:                while (tupcnt--)
        !            90:                {
        !            91:                        getbatch(&oldtid, Batchhd.tido_size);
        !            92:                        getbatch(oldtup, Batchhd.tupo_size);
        !            93:                        getbatch(newtup, Batchhd.tupn_size);
        !            94:                        getbatch(&newtid, Batchhd.tidn_size);
        !            95: 
        !            96:                        /* if this is a replace or append form the new key */
        !            97:                        if (mode != mdDEL)
        !            98:                        {
        !            99:                                for (j = 0; j <= domcnt; j++)
        !           100:                                        setkey(&si_desc, newkey, keys[j].pt_new, j+1);
        !           101: #                              ifdef xZTR1
        !           102:                                if (tTf(49, 7))
        !           103:                                        printup(&si_desc, newkey);
        !           104: #                              endif
        !           105:                        }
        !           106: 
        !           107:                        /* if this is delete or replace form the old key */
        !           108:                        if (mode != mdAPP)
        !           109:                        {
        !           110:                                for (j = 0; j <= domcnt; j++)
        !           111:                                        setkey(&si_desc, oldkey, keys[j].pt_old, j+1);
        !           112: #                              ifdef xZTR1
        !           113:                                if (tTf(49, 8))
        !           114:                                        printup(&si_desc, oldkey);
        !           115: #                              endif
        !           116:                        }
        !           117: 
        !           118:                        switch (mode)
        !           119:                        {
        !           120: 
        !           121:                          case mdDEL:
        !           122:                                if (i = getequal(&si_desc, oldkey, dumtup, &uptid))
        !           123:                                {
        !           124:                                        if (i > 0)
        !           125:                                                break;
        !           126:                                        syserr("secupdate:getequal %d", i);
        !           127:                                }
        !           128:                                if ((i = delete(&si_desc, &uptid)) < 0)
        !           129:                                        syserr("secupdate:delete %d", i);
        !           130:                                break;
        !           131: 
        !           132:                          case mdREPL:
        !           133:                                /* if the newtup = oldtup then do nothing */
        !           134:                                if (bequal(oldkey, newkey, si_desc.reldum.relwid))
        !           135:                                        break;
        !           136:                                if (i = getequal(&si_desc, oldkey, dumtup, &uptid))
        !           137:                                {
        !           138:                                        if (Batch_recovery && i > 0)
        !           139:                                                goto secinsert;
        !           140:                                        syserr("secupdate:getequal-repl %d", i);
        !           141:                                }
        !           142:                                if (i = replace(&si_desc, &uptid, newkey, TRUE))
        !           143:                                {
        !           144:                                        /* if newtuple is dup of old, ok */
        !           145:                                        if (i == 1)
        !           146:                                                break;
        !           147:                                        /* if this is recovery and old tid not there, try an insert */
        !           148:                                        if (Batch_recovery && i == 2)
        !           149:                                                goto secinsert;
        !           150:                                        syserr("secupdate:replace %d", i);
        !           151:                                }
        !           152:                                break;
        !           153: 
        !           154:                          case mdAPP:
        !           155:                          secinsert:
        !           156:                                if ((i = insert(&si_desc, &uptid, newkey, TRUE)) < 0)
        !           157:                                        syserr("secupdate:insert %d", i);
        !           158:                        }
        !           159:                }
        !           160:                if (i = closer(&si_desc))
        !           161:                        syserr("secupdate:closer %.12s %d", si_desc.reldum.relid, i);
        !           162:        }
        !           163:        if (i < 0)
        !           164:                syserr("secupdate:bad get from indexes %d", i);
        !           165: }

unix.superglobalmegacorp.com

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