/****************************************************************************
  module      : vkb06
  author      : JuergenA
  responsible : UweH
  special area: KB_init_config
  created     : 1980-02-15
  last changed: 2000-01-07  12:00
  see also    :
  description :
*****************************************************************************/
 
.tt 1 $SAP$LiveCache$VKB06$
.tt 3 $UweH$KB_init_config$2000-08-18$
 
.nf
 
 
    ========== licence begin  GPL
    Copyright (C) 2000 SAP AG
 
    This program is free software; you can redistribute it and/or
    modify it under the terms of the GNU General Public License
    as published by the Free Software Foundation; either version 2
    of the License, or (at your option) any later version.
 
    This program is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    GNU General Public License for more details.
 
    You should have received a copy of the GNU General Public License
    along with this program; if not, write to the Free Software
    Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
    ========== licence end
 
.fo
***********************************************************
 
Module  : KB_init_config
 
Define  :
 
        PROCEDURE
              k06add_config (VAR m : tgg00_MessBlock; is_cold : boolean);
 
        PROCEDURE
              k06init_config (VAR m : tgg00_MessBlock);
 
        PROCEDURE
              k06linit_local_site (VAR t : tgg00_TransContext);
 
        PROCEDURE
              k06shutdown_filesystem (VAR t : tgg00_TransContext);
 
        PROCEDURE
              k06termset_init (VAR t : tgg00_TransContext);
 
.CM *-END-* define --------------------------------------
.sp;.cp 3
Use     :
 
        FROM
              KB_Logging : VKB560;
 
        PROCEDURE
              kb560InitLogForNewDatabase (TaskId : tsp00_TaskId);
 
        PROCEDURE
              kb560NewLogSize (NewLogSize : tsp00_Int4);
 
      ------------------------------ 
 
        FROM
              KB_restart_record : VKB57;
 
        VAR
              k57restartrec : tkb00_PagePtr;
 
        PROCEDURE
              k57create_restartrecord (VAR t : tgg00_TransContext);
 
        PROCEDURE
              k57save_restartrecord (TaskId : tsp00_TaskId);
 
      ------------------------------ 
 
        FROM
              Systeminfo_cache : VAK10;
 
        PROCEDURE
              a10expand_rec (VAR rec_buf : tgg_rec_buf;
                    VAR b_err : tgg_basis_error);
 
      ------------------------------ 
 
        FROM
              AK_SERVERDB : VAK31;
 
        PROCEDURE
              a31cold_site_get (VAR t : tgg00_TransContext;
                    VAR serverdb    : tsp_dbname;
                    VAR stand_alone : boolean;
                    VAR site        : tgg_serverdb_no);
 
      ------------------------------ 
 
        FROM
              filesysteminterface_1 : VBD01;
 
        VAR
              b01blankfilename  : tsp00_VFilename;
 
        PROCEDURE
              b01create_filesystem (
                    VAR t       : tgg00_TransContext;
                    VAR DBIdent : tsp00_Line );
 
        PROCEDURE
              b01fcreate_file (VAR t : tgg00_TransContext;
                    VAR file_id    : tgg00_FileId;
                    stringcol_cnt  : tsp00_Int2;
                    varcol_cnt_off : tsp00_Int2;
                    no_tree_index  : boolean);
 
        PROCEDURE
              b01filestate (VAR t : tgg00_TransContext;
                    VAR file_id : tgg00_FileId);
 
        PROCEDURE
              b01shutdown_filesystem (VAR t : tgg00_TransContext);
 
      ------------------------------ 
 
        FROM
              filesysteminterface_2 : VBD02;
 
        PROCEDURE
              b02next_record (VAR t : tgg00_TransContext;
                    VAR file_id : tgg00_FileId;
                    VAR rk      : tgg00_Lkey;
                    inclusive   : boolean;
                    VAR b       : tgg00_Rec);
 
      ------------------------------ 
 
        FROM
              pagestore : VBD10;
 
        PROCEDURE
              bd10FlushConverterSerial (VAR Trans : tgg00_TransContext;
                    VAR ConverterVersion           : tsp00_Int4;
                    VAR MaxStaticPageNo            : tsp00_PageNo;
                    VAR MaxDynamicPageNo           : tsp00_PageNo;
                    VAR PackedConvRootBlockAddress : tsp00_Int4);
 
      ------------------------------ 
 
        FROM
              filedirectory : VBD17;
 
        FUNCTION
              bd17GetFdirRoot : tsp00_PageNo;
 
        FUNCTION
              bd17GetLongFdirRoot : tsp00_PageNo;
 
      ------------------------------ 
 
        FROM
              systembufferinterface : VBD20;
 
        PROCEDURE
              bd20FlushDataCache (VAR t : tgg00_TransContext);
 
      ------------------------------ 
 
        FROM
              BD_Wrapper : VBD999;
 
        FUNCTION
              bd999AddDataDevice(
                    TaskId      : tsp00_TaskId;
                    IsCold      : boolean;
                    VAR DevName : tsp00_VFilename;
                    DevSize     : tsp00_Int4;
                    DevNo       : tsp00_Int2 ) : boolean;
 
        FUNCTION
              bd999AddLogDevice(
                    VAR Trans       : tgg00_TransContext;
                    IsCold          : boolean;
                    VAR DevName     : tsp00_VFilename;
                    VAR MirrDevName : tsp00_VFilename;
                    DevSize         : tsp00_Int4;
                    DevNo           : tsp00_Int2;
                    VAR NewLogSize  : tsp00_Int4 ) : boolean;
 
        FUNCTION
              bd999LogIsMirrored : boolean;
 
      ------------------------------ 
 
        FROM
              Configuration_Parameter : VGG01;
 
        VAR
              g01localsite      : tgg_serverdb_no;
              g01stand_alone    : boolean;
              g01tabid          : tgg_tabid_globals;
              g01serverdb_ident : tgg_serverdb_ident; (* PTS 1113051 E.Z. *)
 
        FUNCTION
              g01maxdatadevspaces : tsp_int4;
 
        FUNCTION
              g01maxlogdevspaces : tsp_int4;
 
      ------------------------------ 
 
        FROM
              Codetransformation_and_Coding : VGG02;
 
        PROCEDURE
              g02init;
 
        PROCEDURE
              g02termsetinit (VAR termset : tgg00_TermsetRecord);
 
      ------------------------------ 
 
        FROM
              Regions_and_Longwaits : VGG08;
 
        VAR
              g08savepoint : tsp00_RegionId;
 
      ------------------------------ 
 
        FROM
              Kernel_move_and_fill : VGG10;
 
        PROCEDURE
              g10mv (mod_id    : tsp_c6;            mod_num  : tsp_int4;
                    source_upb : tsp_int4;          dest_upb : tsp_int4;
                    VAR source : tsp00_Key;         src_pos  : tsp_int4;
                    VAR destin : tsp00_Key;         dest_pos : tsp_int4;
                    length     : tsp_int4;
                    VAR e      : tgg_basis_error);
 
      ------------------------------ 
 
        FROM
              RTE_kernel : VEN101;
 
        PROCEDURE
              vbegexcl (pid : tsp_process_id;
                    region  : tsp_region_id);
 
        PROCEDURE
              vendexcl (pid : tsp_process_id;
                    region  : tsp_region_id);
 
        PROCEDURE
              vget_uniqe_id (VAR uniqe_id : tsp_line);
&       ifdef TRACE
 
      ------------------------------ 
 
        FROM
              Test_Procedures : VTA01;
 
        PROCEDURE
              t01line (debug : tgg00_Debug; VAR ln : tsp00_Line);
 
        PROCEDURE
              t01name (debug : tgg00_Debug; nam  : tsp00_Name);
&       endif
 
.CM *-END-* use -----------------------------------------
.sp;.cp 3
Synonym :
 
        PROCEDURE
              g10mv;
 
              tsp_moveobj tsp00_Key
 
.CM *-END-* synonym -------------------------------------
.sp;.cp 3
Author  :  JuergenA
.sp
.cp 3
Created : 1982-11-12
.sp
.cp 3
.sp
.cp 3
Release :      Date : 2000-08-18
.sp
***********************************************************
.sp
.cp 10
.fo
.oc _/1
Specification:
.sp
Procedure K06ADD_CONFIG
.sp
Adds a new devspace and mirror devspace to the config records.
.sp 2;.cp 3
Procedure K06ALTER_DEV
.sp
The procedure alters the devspace description contained in the
config records.
.br;.nf
Call:
1) mess_type  = m_change
   mess2_type = mm_device
   part2.buf  = system devspace name + continuation of part1
.sp
2) mess_type  = m_change
   mess2_type = mm_device_restore
.sp 2;.cp 4
Procedure K06C_ALTER_CONFIG
.sp
This procedure initializes a database or alters the configuration
parameters:
.sp;.nf;.cp 2
.oc _/1;ALTER_CONFIG:
mess_type  = m_change
mess2_type = mm_config
.sp 2;.cp 3
Procedure K06GET_CONFIG
.sp
Reads the config records and writes the config values into the message
buffer.
.br;.nf
CALL:
mess_type  = m_get
mess2_type = mm_config
part1_len  = maxdevnamelength
part1.buf  = system devspace name
.sp;.cp 2;.fo
RESULT:
.br;Part1 contains the configuration values
(structure same as INIT CONFIG, continuation in part2)
.sp 3;.cp 5
Procedure K06GET_DEVICE_CONFIG
.sp
The values contained in the config records CONF and MIRROR_CONF
are written into the message buffer.
.br;.nf
CALL:
mess_type  = m_get
mess2_type = mm_device
.sp;.cp 2;.fo
RESULT:
.br;Part1 contains the configuration values
(structure same as INIT CONFIG, continuation in part2)
.sp 3;.cp 4
Procedure K06INIT_CONFIG
.sp
This procedure initializes a database or alters the configuration
parameters:
.sp;.nf;.cp 2
.oc _/1;INIT_CONFIG:
mess_type  = m_init_config
mess2_type = mm_nil / mm_database_noformat
.sp 2;.cp 3
Procedure K06INT_TO_MESS
.sp
Transforms a four byte integer into printable characters and assigns
these characters to the message buffer.
.sp 2;.cp 3
Procedure KB06ALTER_LOG
.sp
Fragment of a procedure for ALTER DEVICE CONFIG.
.sp 2;.cp 3
Procedure KB06CONFIG_TO_MESS
.sp
Transfers the values contained in the two config records into
a printable character strings and writes these strings
into the message buffer.
.sp 2;.cp 3
Procedure KB06DEVNAME_FROM_BUF
.sp
Reads a devspace name from the specified buffer.
.sp 2;.cp 3
Procedure KB06HEX_FROM_MESS
.sp
Reads two message buffer bytes which represent a hex value
and transforms these value into a character.
.sp 2;.cp 3
Procedure KB06HEX_TO_MESS
.sp
Transforms a character into a two printable hex bytes
and assignes these bytes to the message buffer.
.sp 2;.cp 3
Procedure KB06INIT_DEVSPACE
.sp
Reads the devspace name and the devspace
size from the message buffer and assignes these values to the
first config record CONF.
.sp 2;.cp 3
Procedure KB06INIT_MIRROR_DEV
.sp
Reads all mirror devspace names
from the message buffer and assignes these values to the
second config record MIRROR_CONF.
.sp 2;.cp 3
KB06INIT_WITH_CONFIG_REC
.sp
Creates the system catalog files and the restart record using
the parameters contained in the config records.
.sp 2;.cp 3
KB06INT_FROM_MESS
.sp
Transforms the digits contained in the message buffer into a
four byte integer.
.sp 2;.cp 3
Procedure KB06T_DEVNAME_TO_BUF
.sp
Writes a devspace name into the message buffer.
.CM *-END-* specification -------------------------------
.cp 5;.nf
.sp 2
***********************************************************
.sp
.cp 15
.fo
.oc _/1
Description:
.sp 2;.nf
.oc _/1;Configuration_commands
.sp 2;.cp 6
ALTER DEVICE CONFIG <sys devspace>
.sp
KB-procedure  : K06ALTER_DEV
mess_type     : m_change, mm_device
mess.part1.buf: sql_packet.part2 (<= maxbufferlength)
mess.part2.buf: sql_packet.part2 (> maxbufferlength)
.sp 2;.cp 6
ALTER DEVICE CONFIG RESTORE
.sp
KB-procedure  : K35ALTER_DEV_RESTORE
mess_type     : m_change, mm_device_restore
mess.part1.buf: sql_packet.part2 (<= maxbufferlength)
mess.part2.buf: sql_packet.part2 ( > maxbufferlength)
.sp 2;.cp 5
GET CONFIG
.sp
KB-procedure    : K06GET_CONFIG
mess_type       : m_get, mm_config
sql_packet.part2: mess.part1.buf || mess.part2.buf
.sp 2;.cp 5
GET DEVICE CONFIG
.sp
KB-procedure    : k35GET_DEVICE_CONFIG
mess_type       : m_get, mm_device
sql_packet.part2: mess.part1.buf || mess.part2.buf
.sp 2;.cp 6
INIT CONFIG
.sp
KB-procedure  : K06INIT_ALTER_CONFIG
mess_type     : m_init_config, mm_nil
mess.part1.buf: sql_packet.part2 (<= maxbufferlength)
mess.part2.buf: sql_packet.part2 ( > maxbufferlength)
.CM *-END-* description ---------------------------------
.fo
.sp 2
***********************************************************
.sp
.cp 10
.nf
.oc _/1
Structure:
 
.CM *-END-* structure -----------------------------------
.sp 2
**********************************************************
.sp
.cp 10
.nf
.oc _/1
.CM -lll-
Code    :
 
 
CONST
      c_inclusive        = true;
      c_no_tree_index    = true;
 
 
(*------------------------------*) 
 
PROCEDURE
      k06add_config (VAR m : tgg00_MessBlock;
            is_cold        : boolean);
 
VAR
      NewLogSize : tsp00_Int4;
      Nam        : tsp00_Sname;
 
BEGIN
m.mb_trns^.trError_gg00 := e_ok;
IF  (m.mb_trns^.trError_gg00 = e_ok) AND (m.mb_type2 = mm_device)
THEN
    BEGIN
    IF  (m.mb_qual^.mut_dev = b01blankfilename)
    THEN
        m.mb_trns^.trError_gg00 := e_devname_invalid
    ELSE
        IF  g01maxdatadevspaces >= csp2_max_data_devs
        THEN
            m.mb_trns^.trError_gg00 := e_too_many_devspaces
        (*ENDIF*) 
    (*ENDIF*) 
    END;
(*ENDIF*) 
IF  (m.mb_trns^.trError_gg00 = e_ok) AND (m.mb_type2 = mm_log)
THEN
    BEGIN
    IF  (m.mb_qual^.mut_dev = b01blankfilename)
        OR
        (bd999LogIsMirrored AND (m.mb_qual^.mut_dev2 = b01blankfilename))
    THEN
        m.mb_trns^.trError_gg00 := e_devname_invalid
    ELSE
        IF  g01maxlogdevspaces >= csp2_max_log_devs
        THEN
            m.mb_trns^.trError_gg00 := e_too_many_devspaces
        (*ENDIF*) 
    (*ENDIF*) 
    END;
(* m.qual.mut_count -> wanted devsize *)
(*ENDIF*) 
IF  (m.mb_trns^.trError_gg00 = e_ok) AND (m.mb_qual^.mut_count <= 0) (* PTS 1118732 2002-10-31 *)
THEN
    m.mb_trns^.trError_gg00 := e_devsize_invalid;
(*ENDIF*) 
IF  m.mb_trns^.trError_gg00 = e_ok
THEN
    BEGIN
    IF  m.mb_type2 = mm_log
    THEN
        BEGIN
        IF  bd999AddLogDevice(m.mb_trns^, is_cold,
            m.mb_qual^.mut_dev, m.mb_qual^.mut_dev2,
            m.mb_qual^.mut_count, m.mb_qual^.mut_index_no, NewLogSize)
        THEN
            kb560NewLogSize (NewLogSize)
        ELSE
            m.mb_trns^.trError_gg00 := e_new_disk_not_accessible;
        (*ENDIF*) 
        END
    ELSE
        BEGIN
        IF  NOT bd999AddDataDevice( m.mb_trns^.trTaskId_gg00, is_cold,
            m.mb_qual^.mut_dev, m.mb_qual^.mut_count, m.mb_qual^.mut_index_no )
        THEN
            m.mb_trns^.trError_gg00 := e_new_disk_not_accessible;
        (*ENDIF*) 
        END
    (*ENDIF*) 
    END
(*ENDIF*) 
END;
 
(*------------------------------*) 
 
PROCEDURE
      k06init_config (VAR m : tgg00_MessBlock);
 
VAR
      ConverterVersion           : tsp00_Int4;
      MaxStaticPageNo            : tsp00_PageNo;
      MaxDynamicPageNo           : tsp00_PageNo;
      PackedConvRootBlockAddress : tsp00_Int4;
      DBIdent                    : tsp00_Line;
 
BEGIN
vget_uniqe_id (DBIdent);
m.mb_trns^.trError_gg00 := e_ok;
b01create_filesystem (m.mb_trns^, DBIdent );
IF  m.mb_trns^.trError_gg00 = e_ok
THEN
    b01fcreate_file (m.mb_trns^, g01tabid.sys1_cat, 0,
          cgg_nil_varcol_cnt_off, NOT c_no_tree_index);
(*ENDIF*) 
IF  m.mb_trns^.trError_gg00 = e_ok
THEN
    b01fcreate_file (m.mb_trns^, g01tabid.sys2_cat, 0,
          cgg_nil_varcol_cnt_off, NOT c_no_tree_index);
(*ENDIF*) 
IF  m.mb_trns^.trError_gg00 = e_ok
THEN
    BEGIN
    vbegexcl (m.mb_trns^.trTaskId_gg00, g08savepoint);
    k57create_restartrecord (m.mb_trns^);
    IF  m.mb_trns^.trError_gg00 = e_ok
    THEN
        bd20FlushDataCache (m.mb_trns^);
    (*ENDIF*) 
    IF  m.mb_trns^.trError_gg00 = e_ok
    THEN
        bd10FlushConverterSerial (m.mb_trns^, ConverterVersion ,MaxStaticPageNo,
              MaxDynamicPageNo, PackedConvRootBlockAddress);
    (*ENDIF*) 
    IF  m.mb_trns^.trError_gg00 = e_ok
    THEN
        WITH k57restartrec^, rstConfigParam_kb00 DO
            BEGIN
            crFdirRoot_gg00          := bd17GetFdirRoot;
            crLongDirRoot_gg00       := bd17GetLongFdirRoot;
            rstConverterVersion_kb00 := ConverterVersion;
            crMaxDynamicPno_gg00     := MaxDynamicPageNo;
            crMaxStaticPno_gg00      := MaxStaticPageNo;
            crConvRootBlockAddr_gg00 := PackedConvRootBlockAddress;
            rstDbIdent_kb00          := DBIdent;           (* PTS 1000449 UH 19980909 *)
&           ifdef TRACE
            t01name (kb_log, 'RR: NEW DB_IDENT  ');        (* PTS 1000449 UH 19980909 *)
            t01line (kb_log, rstDbIdent_kb00);             (* PTS 1000449 UH 19980909 *)
&           endif
            END;
        (*ENDWITH*) 
    (*ENDIF*) 
    vendexcl (m.mb_trns^.trTaskId_gg00, g08savepoint);
    IF  m.mb_trns^.trError_gg00 = e_ok
    THEN
        kb560InitLogForNewDatabase (m.mb_trns^.trTaskId_gg00);
    (*ENDIF*) 
    END;
(*ENDIF*) 
IF  m.mb_trns^.trError_gg00 = e_ok
THEN
    BEGIN
    vbegexcl (m.mb_trns^.trTaskId_gg00, g08savepoint);
    k57restartrec^.rstConfigPhase_kb00 := cfpConfigured_ekb00;
    k57save_restartrecord (m.mb_trns^.trTaskId_gg00);
    vendexcl (m.mb_trns^.trTaskId_gg00, g08savepoint)
    END
(*ENDIF*) 
END;
 
(*------------------------------*) 
 
PROCEDURE
      k06linit_local_site (VAR t : tgg00_TransContext);
 
BEGIN
t.trError_gg00 := e_ok;
b01filestate (t, g01tabid.sys1_cat);
IF  t.trError_gg00 = e_ok
THEN
    b01filestate (t, g01tabid.sys2_cat);
(*ENDIF*) 
IF  t.trError_gg00 = e_ok
THEN
    a31cold_site_get (t, g01serverdb_ident.svServerdb_gg00, g01stand_alone,
          g01localsite);
(*ENDIF*) 
END;
 
(*------------------------------*) 
 
PROCEDURE
      k06shutdown_filesystem (VAR t : tgg00_TransContext);
 
VAR
      aux_err : tgg00_BasisError;
 
BEGIN
aux_err  := t.trError_gg00;
t.trError_gg00 := e_ok;
b01shutdown_filesystem (t);
IF  aux_err <> e_ok
THEN
    t.trError_gg00 := aux_err
(*ENDIF*) 
END;
 
(*------------------------------*) 
 
PROCEDURE
      k06termset_init (VAR t : tgg00_TransContext);
 
VAR
      keylen : integer;
      i      : integer;
      k      : tgg00_Lkey;
      rec    : tgg00_BufLenInfo;
 
BEGIN
g02init;
t.trError_gg00 := e_ok;
rec.ri.termsets.term_surrogate := cgg_zero_id;
rec.ri.termsets.term_entrytype := cgg_etermset;
keylen := sizeof (rec.ri.termsets.term_surrogate);
keylen := sizeof (rec.ri.termsets.term_entrytype) + keylen;
k.len  := keylen;
g10mv ('VKB06 ',   1,    
      sizeof (rec.rb.mkey.k), sizeof (k.k),
      rec.rb.mkey.k, 1, k.k, 1, k.len, t.trError_gg00);
i := cgg_begin_termsets;
WHILE (t.trError_gg00 = e_ok) AND (i <= cgg_end_termsets) DO
    BEGIN
    b02next_record (t, g01tabid.sys2_cat, k, NOT c_inclusive, rec.rb);
    IF  t.trError_gg00 = e_key_not_found
    THEN
        t.trError_gg00 := e_ok;
    (*ENDIF*) 
    IF  t.trError_gg00 = e_ok
    THEN
        BEGIN
        k.len := rec.rb.keylen;
        g10mv ('VKB06 ',   2,    
              sizeof (rec.rb.mkey.k), sizeof (k.k),
              rec.rb.mkey.k, 1, k.k, 1, k.len, t.trError_gg00)
        END;
    (*ENDIF*) 
    IF  t.trError_gg00 = e_ok
    THEN
        a10expand_rec (rec.rb, t.trError_gg00);
    (*ENDIF*) 
    IF  t.trError_gg00 = e_ok
    THEN
        BEGIN
        WITH rec.ri.termsets DO
            IF  term_entrytype = cgg_etermset
            THEN
                BEGIN
                IF  term_valid
                THEN
                    BEGIN
                    g02termsetinit (rec.ri.termsets);
                    i := succ(i)
                    END;
                (*ENDIF*) 
                END
            ELSE (* succeeding entrytype *)
                t.trError_gg00 := e_no_next_record
            (*ENDIF*) 
        (*ENDWITH*) 
        END;
    (*ENDIF*) 
    END;
(*ENDWHILE*) 
IF  (t.trError_gg00 = e_no_next_record) OR
    (t.trError_gg00 = e_file_empty)
THEN
    t.trError_gg00 := e_ok
(*ENDIF*) 
END;
 
.CM *-END-* code ----------------------------------------
.SP 2 
***********************************************************
.PA 
