Project

General

Profile

Feature #6320

sharded schemata

Added by Greg Shah over 4 years ago. Updated 11 days ago.

Status:
WIP
Priority:
Normal
Target version:
-
Start date:
Due date:
% Done:

50%

billable:
No
vendor_id:
GCD
case_num:
version_reported:
version_resolved:
reviewer:
production:
No
env_name:
topics:

Related issues

Related to Conversion Tools - Feature #6256: improved profile support Closed
Related to Conversion Tools - Feature #8786: incremental schema conversion and updates New
Related to Conversion Tools - Feature #11404: Implement annotation-based resolution for database dependencies. Review
Related to Conversion Tools - Feature #9639: centralized name management (and conversion) OR jar based resolution New

History

#1 Updated by Greg Shah over 4 years ago

We have multiple customers that split up a large 4GL application into multiple independent modules, each of which can stand on its own or run in combination with some other modules. This gives flexibility at development time (different teams can work on each module) and at deployment time (customers can choose which modules they use).

Evidently, OE allows splitting up the schema for a logical database into multuple standalone .df files (which we are calling "shards"). These can be somehow loaded together as a single database but they are maintained as separate files. Today, FWD can only load a single .df for a logical database. This task is intended to support a list of shards which will be loaded together.

Eric made some related comments in #6256-28.

#2 Updated by Greg Shah over 4 years ago

#3 Updated by Greg Shah about 4 years ago

One customer that uses this feature extensively organizes all activity in apps (each one like an independent module). This means that all development and compilation is done with code that only ever uses a specific sub-set of the overall schema shards. The customer reports that the same 4GL code can fail to compile with a merged schemata (that has all shards).

They found this during a test where they provided a merged schemata and all apps as a single code base. When they tried to compile it in the 4GL, they had to resolve a large number of ambiguous field names as a result. In the 4GL, each app can be compiled separately and then run in the same system with a single database that has all shards present. As long as the compiled code is unambiguous at the time it is compiled, runtime ambiguity will not exist.

FWD needs to support this capability. This means that apps/modules need to be able to be converted in pieces and executed at runtime as a larger system without issues.

#4 Updated by Greg Shah over 2 years ago

  • Related to Feature #8786: incremental schema conversion and updates added

#5 Updated by Greg Shah 7 months ago

This means that apps/modules need to be able to be converted in pieces and executed at runtime as a larger system without issues.

I believe the key here is to put the DMOs from a given profile into a package that is not just specific to the logical name of the database but also include a path segment for the profile. This would create a unique namespace per-profile per logical schema.

#6 Updated by Greg Shah 7 months ago

  • Related to Feature #11404: Implement annotation-based resolution for database dependencies. added

#7 Updated by Greg Shah 7 months ago

+Danut/Alex

#8 Updated by Greg Shah 7 months ago

  • Related to Feature #9639: centralized name management (and conversion) OR jar based resolution added

#9 Updated by Octavian Adrian Gavril 6 months ago

  • Assignee set to Octavian Adrian Gavril
  • Status changed from New to WIP

#10 Updated by Octavian Adrian Gavril 6 months ago

I did some testing in an OE environment and want to see if I got it right regarding how this feature works.
I set up a new progress project with the following architecture:

/BigApplication
  /app1
      /data
          common_shard.df      <-- Defines Table1, Table2
      /src
          code_app1.p

  /app2
      /data
          common_shard.df      <-- Defines Table3, Table4
      /src
          code_app2.p
  main.p

Here is app1/data/common_shard.df:

ADD TABLE "Table1" 
  AREA "Schema Area" 
  DUMP-NAME "table1" 

ADD FIELD "CalcValue" OF "Table1" AS decimal 
  FORMAT "->>>,>>9.99" 
  INITIAL "0" 
  MAX-WIDTH 11

ADD FIELD "Amount" OF "Table1" AS decimal 
  FORMAT "->>>,>>9.99" 
  INITIAL "0" 
  MAX-WIDTH 11

ADD TABLE "Table2" 
  AREA "Schema Area" 
  DUMP-NAME "table2" 

ADD FIELD "CalcResult" OF "Table2" AS decimal 
  FORMAT "->>>,>>9.99" 
  INITIAL "0" 
  MAX-WIDTH 11

and app2/data/common_shard.df
ADD TABLE "Table3" 
  AREA "Schema Area" 
  DUMP-NAME "table3" 

ADD FIELD "LogData" OF "Table3" AS character 
  FORMAT "X(40)" 
  INITIAL "" 
  MAX-WIDTH 80

ADD FIELD "Amount" OF "Table3" AS decimal 
  FORMAT "->>>,>>9.99" 
  INITIAL "0" 
  MAX-WIDTH 11

ADD TABLE "Table4" 
  AREA "Schema Area" 
  DUMP-NAME "table4" 

ADD FIELD "BusinessStatus" OF "Table4" AS character 
  FORMAT "X(20)" 
  INITIAL "" 
  MAX-WIDTH 40

Let's assume we need both data definitions in the same database to run the entire application. However, the issue is that both Table1 and Table3 contain a field named Amount.

This is app1/src/code_app1.p:

DEFINE FRAME myFrame
    CalcValue LABEL "Valoare" 
    Amount    LABEL "Total" 
    WITH 1 COLUMN SIDE-LABELS.

FIND FIRST Table1 NO-LOCK NO-ERROR.
IF AVAILABLE Table1 THEN DO:
    DISPLAY CalcValue Amount WITH FRAME myFrame.
END.  

So, in code_app1.p, we want to use Amount for a frame definition, but before we open a buffer scope for Table1.

Let's say main.p is responsible for compiling code_app1.p:

COMPILE "app1/src/code_app1.p".

If we use a dedicated database for app1 and load its data definition files, main.p runs without errors. However, if we use a shared database where both app1/data/common_shard.df and app2/data/common_shard.df are loaded, compiling code_app1.p produces the following output:

---------------------------
Error (Press HELP to view stack trace)
---------------------------
** Amount is ambiguous with Table1.Amount and Table3.Amount (72)
** C:\Users\Administrator\Progress\Developer Studio 4.3.1\workspace\DfShards\app1\src\code_app1.p Could not understand line 3. (196)

---------------------------
OK   Help   
---------------------------

To resolve this, we must compile code_app1.p in an isolated environment and deploy the resulting code_app1.r binar when connected to the main database. This allows main.p to run without errors, even though the main database contains both Table1.Amount and Table3.Amount.

Does this experiment clearly demonstrate how this feature works, or are there other aspects that haven't been captured yet?

#11 Updated by Greg Shah 6 months ago

At production, the customer will expect a merged database not to run against a shard. This means there is an assumption in this sharded mode is that any tables that get used across applications (across shards) meet one of these conditions:

  • No ambiguity exists across the entire merged database. OR
  • The 4GL code is written to be explicit enough to avoid ambiguity. An example would be for field references to be explicitly qualified.

A customer that uses this sharded concept must enforce one of these, usually through some level of code review or other "discipline" at development time. Leaving this condition in the codebase would be invalid.

#12 Updated by Octavian Adrian Gavril 6 months ago

Understood, that makes perfect sense for production discipline. But does this setup still fundamentally confirm the OE behavior we need to target for this task? Specifically, I'm referring to how the r-code uses its own schema definitions when running against a merged database.

#13 Updated by Greg Shah 6 months ago

Octavian Adrian Gavril wrote:

Understood, that makes perfect sense for production discipline. But does this setup still fundamentally confirm the OE behavior we need to target for this task? Specifically, I'm referring to how the r-code uses its own schema definitions when running against a merged database.

Yes, it correctly describes how the setup would work in OE.

Constantin/Eric: Comments?

#14 Updated by Constantin Asofiei 6 months ago

Greg Shah wrote:

Octavian Adrian Gavril wrote:

Understood, that makes perfect sense for production discipline. But does this setup still fundamentally confirm the OE behavior we need to target for this task? Specifically, I'm referring to how the r-code uses its own schema definitions when running against a merged database.

Yes, it correctly describes how the setup would work in OE.

Constantin/Eric: Comments?

The description is accurate. The compiled r-code disambiguates all field/buffer references; if you run that r-code against a database which has the shard loaded, it will work in OpenEdge.

On our side, there is one more complexity: for runtime conversion, if we keep the .p2o artifacts one per shard, then we will need to know which one to load. But, considering that a runtime query requires the buffers to be specified before parsing it, we can infer from that. Otherwise, we will need a .p2o for the merged schema for runtime.

#15 Updated by Greg Shah 6 months ago

If the details are in annotations in the DMOs, do we need the P2O documents? Annotations seems cleaner.

#16 Updated by Constantin Asofiei 6 months ago

Greg Shah wrote:

If the details are in annotations in the DMOs, do we need the P2O documents? Annotations seems cleaner.

Is not just .p2o, .dict are loaded by SchemaDictionary also, at runtime. We may be able to rebuild this from the DMO annotations if all info is there. We can do it lazily or at once at server startup, but this will add some delay for the FWD server startup or initial query conversion.

#17 Updated by Greg Shah 6 months ago

I think it is best to remove the .dict files too.

#18 Updated by Ovidiu Maxiniuc 6 months ago

Greg Shah wrote:

If the details are in annotations in the DMOs, do we need the P2O documents? Annotations seems cleaner.

The p2o documents are also used for import.

Since they are structured in a tree form, it makes TRPL navigation trivial. In case of import, the p2o is a kind of source of truth (since the .df which was transformed into .p2o should be naturally paired with data stored in the .p files). Rewriting the import to use the annotations is possible, but that direct link is lost. However, since the annotation were basically created from .p2o, and are also stored in application jar, an indirect link still exists.

At any rate, I think moving the import away from TRPL is better. It will couple more the DMOs with the data and will avoid the extra cost of compiling the TRPL source(s). The performance gain would be minimal and only observable in really small databases. The heavy work is (and will be) performed by the import worker.

#19 Updated by Greg Shah 6 months ago

Using TRPL for import is overkill since the tree structure is so trivial. So, yes, I agree it should move away.

#20 Updated by Octavian Adrian Gavril 5 months ago

Greg Shah wrote:

This means that apps/modules need to be able to be converted in pieces and executed at runtime as a larger system without issues.

I believe the key here is to put the DMOs from a given profile into a package that is not just specific to the logical name of the database but also include a path segment for the profile. This would create a unique namespace per-profile per logical schema.

Isn't this already handled by the fact that each module has its own package root?

For example, I've converted app1 and I'm using its JAR file in another empty main app that has a merged .df. When app1 is run in this environment, it will use the com.goldencode.app1.dmo.fwd package.

I understand that we don't support this, but I'm trying to set up an environment that simulates the current problem in FWD.

#21 Updated by Greg Shah 5 months ago

Yes, using a per-module namespace would be a way to solve the issue I noted in #6320-5.

#22 Updated by Octavian Adrian Gavril 19 days ago

I extended the testcase from #6320-11 in OE 11.6 and checked which parts of this task are already covered by #9638 and #11404. A few questions remain before I write the design.

The extended testcase keeps app1/data/common_shard.df, app2/data/common_shard.df and app1/src/code_app1.p from #6320-11 and adds the files below.

extra/dup_table1.df:

ADD TABLE "Table1" 
  AREA "Schema Area" 
  DUMP-NAME "table1" 

ADD FIELD "CalcValue" OF "Table1" AS decimal
  FORMAT "->>>,>>9.99" 
  INITIAL "0" 
  MAX-WIDTH 11

.
PSC
cpstream=ISO8859-1
.
0000000000

extra/extend_field.df:

ADD FIELD "ExtraX" OF "Table1" AS character
  FORMAT "X(10)" 
  INITIAL "" 
  MAX-WIDTH 20

.
PSC
cpstream=ISO8859-1
.
0000000000

extra/extend_label.df:

UPDATE FIELD "Amount" OF "Table1" 
  FORMAT "->>9.9" 
  LABEL "Suma" 

.
PSC
cpstream=ISO8859-1
.
0000000000

extra/extend_index.df:

ADD INDEX "ixAmount" ON "Table1" 
  AREA "Schema Area" 
  INDEX-FIELD "Amount" ASCENDING

.
PSC
cpstream=ISO8859-1
.
0000000000

app1/src/code_create.p:

CREATE Table1.
ASSIGN CalcValue = 2 Amount = 9.
EXPORT Table1.

app1/src/code_label.p:

FIND FIRST Table1 NO-LOCK.
DISPLAY Amount.

app1/src/code_dyn.p:

DEFINE VARIABLE hBuf AS HANDLE NO-UNDO.

CREATE BUFFER hBuf FOR TABLE "Table3".
DISPLAY VALID-HANDLE(hBuf) LABEL "Table3 buffer".
FOR EACH _file NO-LOCK WHERE NOT _file._hidden:
    DISPLAY _file._file-name.
END.

check.p:

FOR EACH Table1 NO-LOCK:
    DISPLAY Table1.CalcValue Table1.Amount Table1.ExtraX (Table1.ExtraX = ?) LABEL "ExtraX unknown".
END.

To reproduce it, connect every database with the same logical name bigdb and follow these steps:
  1. Create a database app1db and load app1/data/common_shard.df into it. Compile code_app1.p, code_create.p, code_label.p and code_dyn.p against it with SAVE.
  2. Create a database mergeddb and load both common_shard.df files into it. Then load extra/dup_table1.df, which fails with TABLE already exists with name Table1.
  3. Run code_dyn.r against mergeddb. The Table3 buffer is created and _file lists Table1 to Table4, although app1db had no Table3.
  4. Create a database fielddb from both common_shard.df files and extra/extend_field.df. Run code_create.r, code_app1.r and check.p against it. EXPORT writes 2 9 without ExtraX, code_app1.r shows the record, and check.p shows that ExtraX holds its INITIAL value, not the unknown value.
  5. Create a database labeldb from both common_shard.df files and extra/extend_label.df. Run code_create.r and code_label.r against it. The field is shown with the label Amount and the format from app1/data/common_shard.df, not with Suma and ->>9.9.
  6. Create a database indexdb from both common_shard.df files and extra/extend_index.df. Run code_create.r and code_app1.r against it. code_create.r works, but code_app1.r stops with Unable to locate index 'default' on table 'Table1' (7967), as Table1 had no index in app1/data/common_shard.df and the new index replaced the default one.

The parts related to this task which are not done yet are the database .p2o, the .dict and the import. The class and temp-table .p2o and the lookup of permanent tables from jars (#11404) are already done in 9638a. 9638a still reads the database .p2o for schema/import, schema/reindex and schema/word_reindex, which #9638-104 left for this task. The .dict is still read by the parser during conversion and by the query conversion at runtime. Moving the import away from TRPL was agreed in #6320-15.

Greg, these are my questions:
  1. Do the customers' shards hold only whole tables, or does a shard also extend tables of another shard (steps 4 to 6)? The FWD .df parser accepts only whole ADD TABLE blocks today, so I would support whole-table shards first.
  2. With whole-table shards, is one DMO per table enough, converted by the module which owns the shard and read from its jar by the other modules? The per-module package from #6320-5 gives one table several DMOs which the runtime has to map to the same table, and I think it is needed only when shards extend each other's tables.
  3. Is a list of import-file elements under namespace (#6256-28) the right way to declare the shards, with each profile listing only the shards of its module?
  4. Which task should take these parts? The database .p2o and the .dict read by the parser fit the goal of #11404, while the runtime .dict and the import away from TRPL come from the discussion here. Should they be done in #11404, in this task or in separate tasks?

#23 Updated by Greg Shah 18 days ago

Do the customers' shards hold only whole tables, or does a shard also extend tables of another shard (steps 4 to 6)? The FWD .df parser accepts only whole ADD TABLE blocks today, so I would support whole-table shards first.

I don't know for sure but I would be very surprised if it were possible to have a single table definition split across .df files in OE. Please try to accomplish this. If it can't be done then we have our answer. If you can find a way to do it, then we need to ask our customers if they use that "feature". Overall, I would not want to implement it unless needed. The idea is an anti-pattern as it would be very fragile and would only work if the separated dev teams kept very careful discipline.

With whole-table shards, is one DMO per table enough, converted by the module which owns the shard and read from its jar by the other modules?

Yes, this is in fact what I expected.

The per-module package from #6320-5 gives one table several DMOs which the runtime has to map to the same table, and I think it is needed only when shards extend each other's tables.

No, that was not my plan for #6320-5. We would not want multiple DMOs per table. I don't see why that is useful.

Is a list of import-file elements under namespace (#6256-28) the right way to declare the shards, with each profile listing only the shards of its module?

#6256-28 is showing a namespace configuration that is outside of any given profile. In other words, it is defining a logical database that is not specific to a profile.

Which task should take these parts? The database .p2o and the .dict read by the parser fit the goal of #11404, while the runtime .dict and the import away from TRPL come from the discussion here. Should they be done in #11404, in this task or in separate tasks?

Unless the #11404 work is current active, just do what is needed here and leave the rest for #11404. If both are done in parallel, then they would probably best be done in one branch otherwise the changes will have a lot of conflicts causing merge issues.

#24 Updated by Octavian Adrian Gavril 18 days ago

I went through the steps of #6320-20 again by hand in Developer Studio, to check each result and the behaviour behind it. When the steps are run from a GUI session, the output of steps 4 to 6 has to go to a file with OUTPUT TO, because EXPORT cannot write to the screen there (error 1105).

I would be very surprised if it were possible to have a single table definition split across .df files in OE. Please try to accomplish this. If it can't be done then we have our answer. If you can find a way to do it, then we need to ask our customers if they use that "feature".

It can be done, and steps 4 to 6 of #6320-20 do it. Table1 is defined in app1/data/common_shard.df, and three separate .df files extend it. extra/extend_field.df adds a field, extra/extend_label.df changes the label and format of Amount, and extra/extend_index.df adds an index. All three load without errors, as this is the same mechanism as the incremental .df which the Data Dictionary writes for a schema change. The r-code compiled against app1/data/common_shard.df alone behaves like this on the extended table:
  • It keeps running and sees only the fields it was compiled with (EXPORT writes 2 9 without ExtraX).
  • A record it creates gets the INITIAL value of the added field, not the unknown value.
  • It keeps the label and format it was compiled with.
  • It stops with error 7967 after the added index, because Table1 had only the default index, which the new index replaced.

Can you ask the customers whether their shards extend tables of other shards? Until we know, I will design for shards which hold only whole tables.

No, that was not my plan for #6320-5. We would not want multiple DMOs per table.

Understood. Each table gets one DMO, in the package of the module which owns its shard, and the other modules read it from that module's jar.

#6256-28 is showing a namespace configuration that is outside of any given profile. In other words, it is defining a logical database that is not specific to a profile.

Understood. I would configure the same logical database in two places:
  • The project which builds the merged database lists all the shards, as in #6256-28. The DDL, the import and the runtime use this whole database.
  • The project of each module, converted app-by-app, lists only the shards which that module owns.

For example, with the shards of #6320-11 and a module app2 which also uses Table1:

<!-- merged database -->
<namespace name="bigdb">
   <import-file path="app1/data/common_shard.df" />
   <import-file path="app2/data/common_shard.df" />
</namespace>

<!-- conversion of app2 -->
<namespace name="bigdb">
   <import-file path="app2/data/common_shard.df" />
</namespace>

When app2 is converted, Table3 and Table4 are parsed from its own .df and get their DMOs in the package of app2. Table1 and Table2 are not parsed again. They come from the DMOs in the jar of app1, which is on the conversion classpath of app2. The tables of modules which app2 does not depend on stay invisible, as they were not in its compile database in OE either. Seeing them could make an unqualified field ambiguous, as the second shard does in #6320-11. Does this match what you have in mind?

Unless the #11404 work is current active, just do what is needed here and leave the rest for #11404. If both are done in parallel, then they would probably best be done in one branch otherwise the changes will have a lot of conflicts causing merge issues.

The #11404 work is active, as its first part is already in 9638a, so I will do this task and the rest of #11404 in one branch.

#25 Updated by Octavian Adrian Gavril 17 days ago

The design of this task, together with the rest of #11404, is ready, and its implementation has to start from 9638a. This note sums up the strategy and the order of the work.

The starting point is the setup of #6320-10 and the answers in #6320-23. A logical database is split into several .df files (shards), each module of the application is compiled against only the shards it uses, and in production all modules run against one merged database which holds every shard.

The picture below shows how FWD handles this with two modules, where app2 uses tables of app1.

  app1 project                      app2 project (depends on app1)
  shards: app1.df                   shards: app2.df
        |                                 |
        v                                 v
  convert app1  ------------------>  convert app2
        |       app1.jar is on the        |   the tables of app1 come from
        |       classpath of app2         |   the DMO annotations in app1.jar
        v                                 v
     app1.jar                          app2.jar
  (DMOs of Table1, Table2)          (DMOs of Table3, Table4)
        |                                 |
        +----------------+----------------+
                         v
          assembly of the merged database
          (all shards in load order: DDL, dump names,
           one index of all DMOs, duplicate checks)
                         |
                         v
          one server and one merged database
          (import, dynamic queries, _file and _field from the DMOs)
The design rests on these choices:
  • The shards of a logical database are listed in load order as import-file children of its namespace (#6256-28).
  • Each module is converted app-by-app in its own project, which lists only the shards it owns. The global parameters module and depends name the module and the modules whose tables it uses.
  • Every table has one DMO, generated by the module which owns its shard. The other modules read it from that module's jar (#6320-23), through the DMO annotations, with no .dict or .p2o (#6320-15, #6320-17).
  • A module sees its own shards and those of the modules it depends on, and nothing else, as its OE compile database did. An unqualified field which matches fields of tables of different shards fails the conversion of that file, as OE fails the compile with error 72 (#6320-10).
  • A separate assembly step builds the merged database from the module jars: the DDL, the dump names and one index of all DMOs. A table or sequence defined twice is an error.
  • The runtime works on the merged database without .p2o or .dict. The server finds the DMOs through that index, and dynamic queries build their schema from the annotations.
  • The import moves away from TRPL (#6320-18, #6320-19) and reads the same index and annotations.
  • A project with a single .df converts and runs as today.
  • A shard holds whole tables. A shard which extends a table of another shard is reported as an error until the customers answer the question of #6320-24.

The reason why the implementation waits for 9638a is that the design builds on what 9638a already does for #11404: the SchemaModel of the converted tables and the lookup of permanent tables from jars. As #6320-23 asks to do #11404 and this task in one branch when both are active, 6320a takes 9638a once it is merged, instead of starting from trunk and conflicting with it later.

Once 9638a is merged, the implementation follows these steps, each one started from failing tests:
  1. The configuration and the loading of the shards, with the checks for tables and sequences defined twice.
  2. The conversion of a module: the tables of its dependencies from their jars, DMOs only for its own tables, and the ambiguity check across shards.
  3. The assembly of the merged database.
  4. The runtime without .p2o and .dict: the discovery of the DMOs, the sequences, _file and the other metaschema tables, and the dynamic queries.
  5. The import and the reindex without TRPL.
  6. The incremental conversion, the removal of the database .p2o from the conversion, and a check that single .df projects convert as before.

The behaviour this design reproduces is recorded in a suite of OpenEdge 11.6 scenarios, and the FWD acceptance tests compare the conversion and the output of each module with it.

#26 Updated by Greg Shah 17 days ago

as this is the same mechanism as the incremental .df which the Data Dictionary writes for a schema change

We aren't trying to implement an incremental .df facility here. The intention was to implement a shards so that mutually exclusive sections of a single logical database can be maintained by separate teams where each team has their own .df file. I don't think we need to expect each shard to have its own database.

The tables of modules which app2 does not depend on stay invisible, as they were not in its compile database in OE either. Seeing them could make an unqualified field ambiguous, as the second shard does in #6320-11. Does this match what you have in mind?

I am expecting that the code will convert using the merged .df. This is about making things more maintainable, it is not meant to change how the code compiles and it is not meant to make ambiguous code compilable.

The starting point is the setup of #6320-10 and the answers in #6320-23. A logical database is split into several .df files (shards), each module of the application is compiled against only the shards it uses, and in production all modules run against one merged database which holds every shard.

I'm worried we are going too far here.

#27 Updated by Octavian Adrian Gavril 13 days ago

While the answers in #12131 are pending, I am starting the part of this task which does not depend on them, in 6320a:
  • The shards of a logical database are listed in load order as import-file children of its namespace, and all of them are loaded into one schema.
  • A table or a sequence which is defined in two shards is an error.
  • The hints and the incremental conversion work per shard.

What FWD does when a shard changes a table of another shard waits for the answers in #12131. The rest of #11404 (the database .p2o, the .dict and the import without TRPL) starts once 9638a is merged.

#29 Updated by Octavian Adrian Gavril 13 days ago

  • % Done changed from 0 to 50

I committed to 6320a in revision 16833 the part of this task which does not depend on the answers in #12131.

A logical database can now be split into several .df files, called shards. Its namespace in p2j.cfg.xml lists them in load order as import-file elements, and FWD loads all of them, in that order, into one schema, as if they were one .df which holds the shards one after the other.
  • The importFile attribute works as before. Using it together with import-file elements is an error.
  • A table or a sequence which is defined twice, in two shards or in one .df, stops the conversion.
  • Each table takes its hints from the hints file of its own shard, e.g. data/fwd_salesrep.df.hints for data/fwd_salesrep.df.
  • An incremental conversion sees a change in any of the shards.

I tested it on the dataset project, with its fwd database split into one shard per table. These are the files of the test. The two shards are cut from data/fwd.df of the project: each holds one of its two tables, unchanged, followed by the trailer of fwd.df.

abl/shard_tables.p:

/* reads both tables of the fwd database, one from each shard */
FOR EACH Salesrep NO-LOCK:
    FIND FIRST Order WHERE Order.SalesRep = Salesrep.SalesRep NO-LOCK NO-ERROR.
    DISPLAY Salesrep.SalesRep Salesrep.RepName
            (IF AVAILABLE Order THEN Order.Ordernum ELSE 0) LABEL "First order".
END.

data/fwd_order.df:

ADD TABLE "Order" 
  AREA "Order" 
  DUMP-NAME "order" 
  ...

ADD FIELD "Ordernum" OF "Order" AS integer
  FORMAT "zzzzzzzzz9" 
  INITIAL "0" 
  ...
  ORDER 10

...

ADD FIELD "SalesRep" OF "Order" AS character
  FORMAT "x(4)" 
  INITIAL "" 
  ...
  ORDER 160

...

ADD INDEX "OrderNum" ON "Order" 
  AREA "Order" 
  UNIQUE
  PRIMARY
  INDEX-FIELD "Ordernum" ASCENDING

...

.
PSC
cpstream=1252
.
0000005407

data/fwd_salesrep.df:

ADD TABLE "Salesrep" 
  AREA "Misc" 
  DUMP-NAME "salesrep" 
  ...

ADD FIELD "RepName" OF "Salesrep" AS character
  FORMAT "x(30)" 
  INITIAL "" 
  ...
  ORDER 20

...

ADD FIELD "SalesRep" OF "Salesrep" AS character
  FORMAT "x(4)" 
  INITIAL "" 
  ...
  ORDER 1

...

ADD INDEX "SalesRep" ON "Salesrep" 
  AREA "Misc" 
  UNIQUE
  PRIMARY
  INDEX-FIELD "SalesRep" ASCENDING

.
PSC
cpstream=1252
.
0000005407

data/fwd_salesrep.df.hints:

<?xml version="1.0"?>
<hints>
   <schema>
      <table name="salesrep" dmo="SalesAgent" />
   </schema>
</hints>

The fwd namespace in cfg/p2j.cfg.xml:

      <namespace
            name="fwd" 
            default="true" >
         <import-file path="data/fwd_order.df" />
         <import-file path="data/fwd_salesrep.df" />
         <parameter name="ddl-dialects" value="h2,postgresql,mariadb" />
         <dialect-specific name="h2">
            <parameter name="collation" value="en_US_P2J" />
         </dialect-specific>
          <dialect-specific name="postgresql">
            <parameter name="udf" value="sql" />
         </dialect-specific>
     </namespace>

For the incremental conversion, this field is added to Salesrep in data/fwd_salesrep.df, before its first field:

ADD FIELD "Note" OF "Salesrep" AS character
  FORMAT "x(8)" 
  INITIAL "" 
  MAX-WIDTH 16
  ORDER 300

and this field to Order in data/fwd_order.df, before its first field:

ADD FIELD "Note" OF "Order" AS character
  FORMAT "x(8)" 
  INITIAL "" 
  MAX-WIDTH 16
  ORDER 300

These are the steps and their results:
  1. Delete data/fwd.df and rename data/fwd.schema.hints to data/fwd_order.df.hints, the hints file of the first shard.
  2. Run a full conversion. Both shards are imported, the DMO of Salesrep is SalesAgent from the hints file of its shard, and shard_tables.p converts.
  3. Add data/fwd_dup.df, a copy of data/fwd_salesrep.df, as a third import-file and run a full conversion. It stops with Table "Salesrep" of shard data/fwd_dup.df is already defined by shard data/fwd_salesrep.df. Remove the third shard.
  4. Add importFile="data/fwd_order.df" to the namespace, next to the import-file elements, and run a full conversion. It stops with namespace fwd: use either the importFile attribute or import-file elements. Remove the attribute and run a full conversion.
  5. Add the field to Salesrep and run an incremental conversion. SalesAgent gets a note property and the DDL a note column in the salesrep table.
  6. Add the field to Order and run an incremental conversion. The DMO of Order gets a note property and the DDL a note column, while SalesAgent stays as it was.

The database .p2o, the .dict and the import without TRPL stay in #11404, as #6320-23 suggests. The shards do not need them, as the conversion still writes one .p2o and one .dict for the merged schema.

Until the answers in #12131 tell how to continue this implementation, I will keep adding tests for it, so that it is well covered.

#30 Updated by Octavian Adrian Gavril 13 days ago

I committed to 6320a in revision 16834 these fixes for the shards of 16833:
  • A listed shard which does not exist stops the conversion with an error which names every missing shard, e.g. Missing .df file(s) of schema bigdb: data/missing.df. Before, the conversion stopped with a NullPointerException which did not name the file. A mutable schema may still miss a shard, which is then read as empty, as a missing .df of a mutable schema was before.
  • An incremental conversion of a mutable schema with a missing shard sees the changes of the shards which exist. Before, it skipped the whole schema when the first shard was missing, and logged Could not retrieve the modified tables when a later one was missing.
  • The schema reports and the call graph show each table, with its triggers, in the .df of its own shard, and the reports hold the text of every shard. Before, they showed the tables of a later shard in the .df of the first shard, at the line of their own shard.

#31 Updated by Octavian Adrian Gavril 11 days ago

I committed to 6320a in revision 16835 these fixes for the shards in the schema reports and the report server, which I found while reviewing 16834:
  • The schema reports of a mutable schema whose first shard does not exist read the shards which exist. Before, they stopped with a FileNotFoundException on the missing shard.
  • A .df shard which two logical databases list is stored once in the report database. Before, its text could be stored twice, once for each database.
  • A custom schema search shows a table in the .df of its own shard, also with a file filter. Before, it did not find the tables of shards whose file is not named after the schema, and it showed a table of a later shard in the first shard.
  • The source view of a shard shows only the tables of that shard. Before, it also showed the tables of the other shards, at the same line numbers.

#32 Updated by Greg Shah 11 days ago

Does incremental conversion handle deletes and edits?

In other words, are we storing (in the cvtdb) a shard-level hash for shard .df and checking against that?

#33 Updated by Octavian Adrian Gavril 11 days ago

Greg Shah wrote:

Does incremental conversion handle deletes and edits?

In other words, are we storing (in the cvtdb) a shard-level hash for shard .df and checking against that?

Yes. The conversion database keeps a hash of each shard file, so a change in any shard marks the schema as changed. It also keeps a hash of each table, so only the changed tables get a new DMO and DDL. Edits, deleted fields and deleted sequences give the same result as a full conversion.

Two cases still need work:
  • A shard removed from the import-file list is not detected yet.
  • A deleted table is dropped from the DDL, but its DMO stays. This also happens with a single .df before 6320a, so it is not related to the shards, but we can fix that as well.

#34 Updated by Octavian Adrian Gavril 11 days ago

I committed to 6320a in revision 16836 fixes for the two cases which did not work:
  • A shard removed from the import-file list, or listed again, is now detected. Before, only the hashes of the listed shards were checked, so the removed shard's tables stayed in the DMOs and the DDL.
  • The DMO of a deleted table is now deleted. Before, it stayed, also with a single .df, because the conversion no longer stored the DMO file of each table.

Also available in: Atom PDF