CULL to TOM: A Reference for Developers

An empty, dashed form on the left, an arrow handing its content over to a filled form that sits in a stack of filed forms

This is the long one. The first post told the story of making the qmaster’s data layer fast, the second why we replaced CULL with a typed object model, the third gave a short tour of working with it. This post is for the people who have to do the work: developers who know CULL — maybe for twenty years — and now write or convert code that uses TOM.

It is meant as a reference you keep open next to the editor. It maps the whole CULL interface to TOM. It doesn’t do that in alphabetical order, though. Instead it follows one piece of data through the system, from where it is born to where it is used, and every step introduces the calls that step needs, first the way you know them, then the way they are written now.

If you know CULL, you will recognize every line on the left. That’s the point.

How to read this post

The journey: a load report. Every few seconds each execution daemon measures its host — load average, memory, topology, the values of load sensors — packs the values into a report and sends it to the qmaster. The qmaster files them under the host, and the scheduler uses them to decide where jobs go.

Each section is one step of that journey and has the same shape:

  1. Where we are — what the code at this point has to do.
  2. CULL — the code as it was before the conversion.
  3. TOM — the same code with typed handles.
  4. What changed — and why.
  5. Calls in this step — every CULL call the step touches, its TOM counterpart, one line each.
  6. Pitfalls — what goes wrong when converting this kind of code.

All code is real. The TOM side is the 9.2.0alpha1 tree; the CULL side is the same function before the conversion, taken from the git history. Where a few lines in between don’t matter for the step, they are left out as ....

The journey of a load report: in sge_execd the report is created (2), the host measured (4), lists handed over (5) and only changes sent (6); over the wire (7) to sge_qmaster, which finds the host (8) and merges the values (9); events carry the host to the scheduler, which sees a reduced host (11), checks load thresholds (12) and orders the hosts (13)

Functions the journey doesn’t pass are collected in the reference part at the end, grouped by area.

Two forms of TOM appear throughout. The member form, ep.set<F>(value) on a handle, is the one converted code uses; it throws on misuse. The free form, ocs::tom::set<F>(ep, value), takes a raw lListElem * only and keeps the old soft contract (0 or −1). The mechanical first pass of the conversion produced the free form, so you will meet it in the history and in the few places that still hold a raw pointer. Both check the field type at compile time. On a handle the free form doesn’t even compile any more: it would bind to the raw pointer and quietly skip the checks, so it is deleted.

  1. The forms: load value, report, host

Where we are

Before any code runs, there are three types the journey needs: a single load value (LR), the report that carries a list of them (REP), and the host they end up on (EH).

CULL

A CULL type is a descriptor: an array of field definitions, one per field, each with a number, a type and flags. The field numbers are enumerators like LR_name, generated together with the descriptor from a JSON definition. This is the generated header of the load value:

enum {
   LR_name = LR_LOWERBOUND,   ///< Load Variable Name
   LR_value,   ///< Load Variable Value
   LR_global,   ///< Is Global
   LR_is_static,   ///< Is Static
   LR_host   ///< Host Name
};

LISTDEF(LR_Type)
   SGE_STRING(LR_name, CULL_HASH)
   SGE_STRING(LR_value, CULL_DEFAULT)
   SGE_ULONG(LR_global, CULL_DEFAULT)
   SGE_ULONG(LR_is_static, CULL_DEFAULT)
   SGE_HOST(LR_host, CULL_HASH)
LISTEND(LR_Type)

The constant LR_name is just a number. Nothing stops you from passing it with an element of another type, or reading it with lGetUlong(); CULL finds out at run time, if at all.

TOM

TOM uses the same JSON definitions and generates more from them. Per type there is a header sgeobj/tom/ocs_tom_<T>.h (all of them together in ocs_tom_all.h) with a struct for the type and a field table:

enum LR_Field {
   LR_name = LR_LOWERBOUND,
   LR_value,
   LR_global,
   LR_is_static,
   LR_host,
};

namespace ocs::tom {
   struct LR {
      static constexpr FieldInfo fields[] = {
         {LR_name, "LR_name", FieldType::String, Flag::Hash},
         {LR_value, "LR_value", FieldType::String, Flag::None},
         {LR_global, "LR_global", FieldType::Uint32, Flag::None},
         {LR_is_static, "LR_is_static", FieldType::Uint32, Flag::None},
         {LR_host, "LR_host", FieldType::Host, Flag::Hash},
      };
      static constexpr auto descriptor = make_descriptor(fields);
      static constexpr auto names = field_names(fields);
   };
   template <>
   struct TypeOf<LR_Field> {
      using type = LR;
   };
}

The field numbers are the same, but the enumeration now has a name, LR_Field, and TypeOf<LR_Field> ties it to LR. The descriptor is computed from the field table by the compiler. For every list or object field whose element type is known, the generator adds one more line — this is how the host says what its load list holds:

   template <>
   struct SubType<EH_load_list> {
      using type = HL;   ///< the sub-type
   };

Everything the compiler knows about a field is collected in ocs::tom::FieldTraits<F> (tom/ocs_FieldTraits.h): Type (the object type the field belongs to), Sub (the element type of a list or object field, or void), pos, type (the FieldType), hashed, unique and has_sub. That is what every typed call later in this post is checked against.

What changed

The definitions didn’t change; what is generated from them did. That’s why converting a module never touches the JSON files — with one exception, the sub-types of list fields, which comes up in step 10. The XX_Type descriptor names are gone; where code really needs a raw descriptor, it writes ocs::tom::LR::descriptor.e.

Before anything else, every program installs the model once — the counterpart of lInit():

// CULL
lInit(nmv);

// TOM (execd.cc, setup_qmaster.cc)
ocs::tom::install_model(ocs::tom::gcs_model());

Installing is idempotent and cheap when the same model is installed already, and it can also report why a model was rejected.

Calls in this step

CULLTOM
XX_Type (LR_Type, REP_Type, …)the struct ocs::tom::XX; its descriptor XX::descriptor.e only where a raw descriptor is needed
lInit(nmv)install_model(gcs_model())
lNm2Str(nm)field_name(nm) — never nullptr
lStr2Nm(name)find_field(name) — NoName if unknown
lGetType(T_Type, nm), lGetPosTypeFieldTraits<F>::type; at run time field_info(nm)->type, field_type_of(descr[pos].mt)
type name of a descriptortype_name(descr)
field table, sub-typetype_table(nm), sub_type(nm)
lCountDescr, lDumpDescr, lUndumpDescrinternal to the list core now (dump_descr(), undump_descr() in ocs_DumpCore.h)

Pitfalls

  • Without an installed model, field_info(), sub_type() and type_name() return nullptr, find_field() returns NoName, and error messages name fields only by number. A test binary that uses the generated types installs gcs_model() in main() too.

  1. The execd creates a report

Where we are

execd_add_load_report() in daemons/execd/load_avg.cc runs every load report interval. Its first job: create an empty report element.

CULL

lListElem *report;
...
report = lCreateElem(REP_Type);

TOM

auto report = ocs::tom::ElementPtr<ocs::tom::REP>::create();

What changed

lCreateElem() returns a raw pointer, and nothing in the type says who frees it. ElementPtr<REP> is an owning handle: it holds the element, frees it when it goes out of scope, and can’t be copied, only moved — like std::unique_ptr. And it’s an element of type REP, so the next step can check every field against it. create() throws when there is no memory; a nullptr check after it is dead code.

TOM has three element handles, and choosing the right one is most of the conversion work:

Three handles, three promises: ElementPtr owns the element and hands it over with std::move, Element may change an element someone else owns, ConstElement only reads; the list handles are ListPtr, List and ConstList
HandleSaysCULL equivalent
ElementPtr<T>I own this elementlListElem * you must free
Element<T>I may change it, someone else owns itlListElem * inside a list
ConstElement<T>I only read itconst lListElem *

The same three exist for lists: ListPtr<T>, List<T>, ConstList<T>. The non-owning ones are the size of a pointer and are passed by value. From a raw pointer they are made only explicitly, and checked: ocs::tom::Element<ocs::tom::EH>(ep) throws WrongType if ep is not a host. from_typed(ep) skips that check, for places where the type is guaranteed by construction (step 11). Back to a raw pointer they convert implicitly, so a converted function can still call one that isn’t.

Calls in this step

CULLTOM
lCreateElem(T_Type)ElementPtr<T>::create()
lCreateElem(descr) with a reduced descriptorElementPtr<T>::create(layout<F...>()), create(what), create(descr)
lCreateElem(lGetListDescr(lp))ElementPtr<T>::create_like(list) — same layout as the list
lFreeElem(&ep)nothing — the destructor; ep.reset() to free early
lCreateList(name, T_Type)ListPtr<T>::create(name)
lCreateListHash(name, descr, false)ListPtr<T>::create(name, Hashing::Off)
lCreateList(name, lGetListDescr(lp))ListPtr<T>::create_like(name, list)
lReduceDescr(&d, T_Type, what) + lCreateList(name, d)ListPtr<T>::create(name, what), create(name, layout<F...>())
lFreeList(&lp)nothing — the destructor; lp.reset()
sge_free(&d) for a descriptor from lReduceDescr()release_descr(d)
lCreateElemList(name, descr, n)no counterpart — create the list and emplace_back
a raw pointer becomes ownedexplicit checked constructor ElementPtr<T>(ep), ListPtr<T>(lp); adopt<T>(std::move(raw_owner))
an owner becomes rawrelease()

Pitfalls

  • An ElementPtr created in a branch and never handed on is freed at the end of the branch. In CULL that was a leak; in TOM it’s correct — but if the old code relied on the leak (someone else kept the pointer), the conversion turns a leak into a use-after-free. That’s why the rewrite tool refused such paths, see step 15.
  • Process-lifetime state — globals, statics, master lists — stays a raw lList * on purpose. A static ListPtr would run its destructor at exit(), also in forked children. Read such state through checked non-owning handles and free it explicitly with free_raw_list()/free_raw_elem(). The execd’s lr_list and last_lr in step 6 are exactly that.

  1. Filling in the header

Where we are

The report gets its type, the version of the daemon, a sequence number and the host it comes from.

CULL

if (send_all) {
   lSetUlong(report, REP_type, NUM_REP_FULL_REPORT_LOAD);
} else {
   lSetUlong(report, REP_type, NUM_REP_REPORT_LOAD);
}
lSetUlong(report, REP_version, ocs::Version::get_version());
lSetUlong(report, REP_seqno, sge_execd_report_seqno);
lSetHost(report, REP_host, qualified_hostname);

TOM, free form (the mechanical rewrite)

The first, automatic pass turned every accessor into the free form. Same arguments, same return value; only the type check moved to the compiler:

if (send_all) {
   ocs::tom::set<REP_type>(report, NUM_REP_FULL_REPORT_LOAD);
} else {
   ocs::tom::set<REP_type>(report, NUM_REP_REPORT_LOAD);
}
ocs::tom::set<REP_version>(report, ocs::Version::get_version());
ocs::tom::set<REP_seqno>(report, sge_execd_report_seqno);
ocs::tom::set<REP_host>(report, qualified_hostname);

TOM, member form

if (send_all) {
   report->set<REP_type>(NUM_REP_FULL_REPORT_LOAD);
} else {
   report->set<REP_type>(NUM_REP_REPORT_LOAD);
}
report->set<REP_version>(ocs::Version::get_version());
report->set<REP_seqno>(sge_execd_report_seqno);
report->set<REP_host>(ocs::tom::Host(qualified_hostname));

What changed

In CULL the type of the value is in the function name: lSetUlong, lSetHost, lSetString. Pick the wrong one, and you find out at run time — if anyone checks the −1. In TOM there is one set, and the field decides the type. A set<REP_type>("x") doesn’t compile, nor does reading a string field into a number:

// test/libs/tom/compile_fail/string_into_number.cc: does not compile
const ocs::tom::Element<ocs::tom::JB> job{raw};
const std::uint32_t name = job.get<JB_job_name>();

The member form goes further than the free form: it throws instead of returning −1, and host names are a type of their own, ocs::tom::Host, so a host name can’t be confused with any other string. A Host compares like sge_hostcmp() and converts implicitly to const char *; a C string becomes a Host only explicitly, as above.

Calls in this step

CULLTOM member formTOM free form (raw pointer)
lGetUlong, lGetUlong64, lGetInt, lGetLong, lGetDouble, lGetBool, lGetString, lGetHost, lGetRefe.get<F>()get<F>(ep)
lSetUlong, lSetUlong64, lSetInt, lSetLong, lSetDouble, lSetBool, lSetString, lSetRefe.set<F>(v)set<F>(ep, v), returns 0/−1
lSetHoste.set<F>(Host(name))set<F>(ep, name) takes a C string
lGetPosUlong, lSetPosString, … (by position)positions are gone; with a field number known only at run time: e.get<V>(nm), e.set(nm, v) on a raw handleget<V>(ep, nm), set(ep, nm, v)
lGetStringNotNulle.get_or_empty<F>()get_or_empty<F>(ep)
lGetPosViaElem(ep, F, SGE_NO_ABORT) >= 0e.has<F>()has<F>(ep)
lAddUlong, lAddUlong64, lAddDoublee.add<F>(offset) — returns the new valueadd<F>(ep, offset) — returns 0/−1
lXchgStringchar *old = e.exchange<F>(str) — neither string copiedexchange<F>(ep, &str)
lOrUlongBitMask, lAndUlongBitMask, lClearUlongBitMaske.or_bits<F>(m), e.and_bits<F>(m), e.clear_bits<F>(m)or_bits<F>(ep, m), …
lMatchUlongBitMaske.has_any_bits<F>(m)has_any_bits<F>(ep, m)
lGetUlong64Atomic, lSetUlong64Atomice.get_atomic<F>(), e.set_atomic<F>(v)get_atomic<F>(ep), set_atomic<F>(ep, v)
copy one field if the source has itdst.copy_if_present<F>(src)copy_if_present<F>(dst, src)
lGetList, lGetObject, lSetList, lSetObjectstep 5

Pitfalls

  • set<F> on an element of the wrong type doesn’t compile — good. set<F> on an element whose layout is reduced (it came out of a selection, step 11) compiles and throws at run time with AbsentField.
  • auto host = ep.get<LR_host>() is a Host. Passed to printf("%s", host) it is undefined behaviour, as any class through varargs; write host.c_str(). The same holds for DPRINTF, ERROR and sge_dstring_sprintf.
  • Host == "name" compares like host names, not byte-wise. strcmp(host, other) still compiles through the implicit conversion and compares byte-wise; keep it only where the old code did.
  • The member add<F>() returns the new value, the free one 0 or −1. Don’t mix them up when you convert a line that tested the return value.

  1. The list of load values

Where we are

sge_build_load_report() measures the host and returns a list with one LR element per value. Every value goes in through one helper, sge_add_str2load_report() in daemons/execd/sge_report_execd.cc: it looks for a value of that name on that host, adds one if there is none, and sets the value.

CULL

int sge_add_str2load_report(lList **lpp, const char *name, const char *value, const char *host) {
   ...
   lListElem *ep = nullptr;
   const void *iterator = nullptr;
   ...
   if (*lpp != nullptr) {
      lListElem *search_ep = lGetElemHostFirstRW(*lpp, LR_host, host, &iterator);

      while (search_ep != nullptr) {
         if (strcmp(lGetString(search_ep, LR_name), name) == 0) {
            ep = search_ep;
            break;
         }
         search_ep = lGetElemHostNextRW(*lpp, LR_host, host, &iterator);
      }
   }

   if (ep == nullptr) {
      ep = lAddElemStr(lpp, LR_name, name, LR_Type);
      lSetHost(ep, LR_host, host);
      lSetUlong(ep, LR_global, (uint32_t)(strcmp(host, SGE_GLOBAL_NAME) == 0 ? 1 : 0));
      lSetUlong(ep, LR_is_static, sge_is_static_load_value(name));
   }

   lSetString(ep, LR_value, value);
   ...
}

TOM

int sge_add_str2load_report(ocs::tom::ListPtr<ocs::tom::LR> &lpp, const char *name, const char *value,
                            const char *host) {
   ...
   if (!lpp) {
      // created as the free emplace_back() creates a missing list
      lpp = ocs::tom::ListPtr<ocs::tom::LR>::create("");
   }

   DRETURN(sge_add_str2load_report(*lpp, name, value, host));
}

int sge_add_str2load_report(const ocs::tom::List<ocs::tom::LR> lp, const char *name, const char *value,
                            const char *host) {
   ...
   ocs::tom::Element<ocs::tom::LR> ep = nullptr;
   ...
   for (const auto search_ep : lp.find_all<LR_host>(ocs::tom::Host(host))) {
      if (strcmp(search_ep.get<LR_name>(), name) == 0) {
         ep = search_ep;
         break;
      }
   }

   if (ep == nullptr) {
      ep = lp.emplace_back<LR_name>(name);
      ep.set<LR_host>(ocs::tom::Host(host));
      ep.set<LR_global>((uint32_t)(strcmp(host, SGE_GLOBAL_NAME) == 0 ? 1 : 0));
      ep.set<LR_is_static>(sge_is_static_load_value(name));
   }

   ep.set<LR_value>(value);
   ...
}

What changed

  • The out-parameter became an owner. lList **lpp meant “a list I may create, owned by the caller”; ListPtr<LR> & says the same in the type. The function splits in two: the outer one creates the list when it’s missing — which lAddElemStr() did as a side effect — and the inner one works on a non-owning List<LR>.
  • The lookup loop lost its bookkeeping. No iterator, no “first” and “next” call to keep in step: find_all<LR_host>(Host(host)) is a range over every element with that key, using the field’s hash table where there is one.
  • lAddElemStr() became emplace_back<LR_name>(name). It creates the element with the list’s layout, sets the key and returns a handle on it.

The caller walks the list the same way. Here is the derived-value part of sge_build_load_report(), first CULL, then TOM:

// CULL
ep = lGetElemStrFirst(lp, LR_name, LOAD_ATTR_NUM_PROC, &iterator);
while (ep != nullptr) {
   const char *value = lGetString(ep, LR_value);

   if (sge_hostcmp(lGetHost(ep, LR_host), qualified_hostname) == 0) {
      if (value) {
         nprocs = std::max(1, atoi(value));
      }
      break;
   }
   ep = lGetElemStrNext(lp, LR_name, LOAD_ATTR_NUM_PROC, &iterator);
}

// TOM
for (const auto ep : lp->find_all<LR_name>(LOAD_ATTR_NUM_PROC)) {
   const char *value = ep.get<LR_value>();

   if (sge_hostcmp(ep.get<LR_host>(), qualified_hostname) == 0) {
      if (value) {
         nprocs = std::max(1, atoi(value));
      }
      break;
   }
}

Calls in this step

CULLTOM
lAddElemStr(&lp, F, s, T_Type), lAddElemHost, lAddElemUlong, lAddElemUlong64list.emplace_back<F>(key); on a raw holder emplace_back<F>(&lp, key) creates a missing list
lAppendElem(lp, ep)list.push_back(std::move(ep)) — returns an Element<T> on the element now in the list
lInsertElem(lp, nullptr, ep)list.push_front(std::move(ep))
lInsertElem(lp, after, ep)list.insert_after(after, std::move(ep))
for_each_ep, for_each_ep_lv, for_each_rw, for_each_rw_lvfor (auto e : list) — ConstElement<T> on a ConstList<T>, Element<T> on a List<T>
for_each_rev, for_each_rev_rwfor (auto e = list.back(); e; e = e.prev())
lFirst, lFirstRW, lLast, lNext, lPrevlist.front(), list.back(), e.next(), e.prev() — an empty handle at the end
lGetNumberOfElemsize(), empty()
lGetElemStrFirst/Next, lGetElemHostFirst/Next, lGetElemUlongFirst/Next, … and their RW formsfor (auto e : list.find_all<F>(key))
lGetListName, lGetListDescr, lGetElemDescrlist.name(), list.descr(), e.descr()
lCompListDescrlist.same_layout(other)
lGetNumberOfRemainingElemremaining(e)
lGetElemIndexno counterpart

Pitfalls

  • List<T>::emplace_back<F>() needs a list; lAddElemStr(&lp, …) created one when lp was nullptr. Use e.get_or_create<F>() for a list field, or create the list first, as the function above does.
  • A range-for must not erase() its current element and go on. Fetch next() first, exactly as with lNextRW(), or leave the loop right after the erase — step 6 does the latter.
  • An element linked into a list must have the list’s layout. push_back() of a full element into a reduced list throws WrongLayout; emplace_back<F>() and ElementPtr<T>::create_like(list) give the right layout.

  1. Handing over: the list to the report, the report to the report list

Where we are

This is where ownership changes hands twice: the list of load values goes into the report’s REP_list field, and the finished report goes into the list of reports the execd will send.

CULL

tmp_lr_list = sge_build_load_report(qualified_hostname, binary_path);
...
lSortList(tmp_lr_list, order);
lSetList(report, REP_list, tmp_lr_list);
...
lAppendElem(report_list, report);

After lSetList(), tmp_lr_list still points to the list, but the list now belongs to the report. After lAppendElem(), report still points to the report, but it belongs to report_list. Nothing at the call site says so. If someone later adds lFreeList(&tmp_lr_list) at the end of the function because it “looks like a local”, the report holds a dangling pointer. If someone forgets that lSetList() frees the old list, it leaks.

TOM, during the conversion

For a while the old list library accepted handles at its sinks, so a module could be converted variable by variable. This is the function after the ownership pass:

auto report = ocs::tom::ElementPtr<ocs::tom::REP>::create();
...
ocs::tom::set<REP_list>(report, tmp_lr_list);
...
lAppendElem(report_list, std::move(report));

TOM, member form

auto tmp_lr_list = sge_build_load_report(qualified_hostname, binary_path);
...
tmp_lr_list->sort<ocs::tom::asc<LR_host>>();
report->set<REP_list>(std::move(tmp_lr_list));
...
report_list.push_back(std::move(report));

report_list is a List<REP> parameter here, and sge_build_load_report() returns a ListPtr<LR>: the owner comes out of the function as its return value, not through an lList **.

What changed

std::move(report) says in the code what lAppendElem(report_list, report) only did: this function gives the report away. And it says it at the place where you read it.

std::move itself moves nothing. It’s a cast: it turns report into an rvalue, so the overload that takes ElementPtr<REP> && is chosen. The transfer happens inside that function, and only if the store succeeds: a refused store leaves the element with the handle, and its destructor frees it. Afterwards the handle is empty — report == nullptr, and any member call throws EmptyHandle. That’s stricter than the standard library, where a moved-from object is “valid but unspecified”. clang-tidy‘s bugprone-use-after-move finds the leftovers.

A typed list field takes only an owner of its own sub-type. job.set<JB_env_list>(std::move(paths)) with a ListPtr<PN> doesn’t compile — the compile-fail test foreign_list_into_typed_field.cc holds exactly that line. REP_list is different: it takes an owner of any type, because what it holds depends on the report (step 10).

The rule behind it

The ownership pass of the conversion was done by a rewriting tool, and its rule for owning variables is the clearest statement of what CULL code left unsaid. A local lListElem * or lList * became an ElementPtr/ListPtr only if, on every path through the function, the variable ends in exactly one place: a sink (lAppendElem, lSetList, a function taking ownership), a free, or a return. No use after that point. On the null side of an if (t) it owns nothing. A path that ends with the variable still owning — no free, no sink — was refused: maybe a leak, but maybe an unknown callee kept the pointer, and turning that into an automatic free would be a double free. Those cases stayed for the hand conversion.

A variable used for several lists one after the other became several owners. In the scheduler thread, one t held three selections in turn; the pass made three:

// before
t = lSelect(nullptr, qinstance_list, where_what.where_queue, where_what.what_queue2);
if (t) {
   ...
   lAppendList(copy.queue_list, t);
   lFreeList(&t);
}

// after the ownership pass
auto t_qu = ocs::tom::ListPtr<ocs::tom::QU>::from_typed(lSelect(nullptr, qinstance_list, where_what.where_queue, where_what.what_queue2));
if (t_qu) {
   ...
   lAppendList(copy.queue_list, *t_qu);
   t_qu.reset();
}

Calls in this step

CULLTOM
lSetList(ep, F, lp) — takes lp, frees the old liste.set<F>(std::move(list)); e.set<F>(nullptr) frees the list
lSetObject(ep, F, obj)e.set<F>(std::move(obj))
lGetList, lGetObjecte.get<F>() on a ConstElement — a read-only ConstList<Sub>/ConstElement<Sub>
lGetListRW, lGetObject for writinge.get<F>() on an Element — a mutable List<Sub>/Element<Sub>
lGetOrCreateList(ep, F, name, T_Type)e.get_or_create<F>(name) — never an empty handle
lXchgList(ep, F, &lp)auto old = e.exchange<F>(std::move(list)) — returns the old one as an owner
lSwapListe.swap<F, G>(other)
lDechainObject(ep, F)auto obj = e.take<F>() — an ElementPtr<Sub>
lGetListRefe.list_ref<F>() — the lList ** for an unconverted callee
lAppendElem(lp, ep)list.push_back(std::move(ep))
lDechainElem(lp, ep)auto e = list.extract(ep) — an ElementPtr<T>
lRemoveElem(lp, &ep)list.erase(ep)
lAddList(lp, &other) — frees otherlist.splice(std::move(other)) with a ListPtr<T>
lAppendList(lp, other) — other stays, emptylist.splice(other) with a List<T>
lDechainList(lp, &tail, ep)auto tail = list.split_at(ep)

Pitfalls

  • After push_back(std::move(e)) use the returned Element<T>, not e: auto in_list = list.push_back(std::move(e));.
  • erase() frees the element; a handle to it dangles afterwards, like an erased iterator. erase() and extract() of an element of another list throw ForeignList.
  • ConstElement<T> has no constructor from an ElementPtr<T>; pass *owner. List<T> and ConstList<T> view an lvalue ListPtr<T> implicitly, but not a temporary one.
  • During the transition, release() marks a raw destination that is still to be typed: *answer = list.clone().release(). Every release() left in converted code is such a place.

  1. A copy for next time, sorted by host

Where we are

The execd sends a full report only the first time and after a reconnect. Otherwise it sends the changes: it keeps the last list it sent, compares the new values with it, drops what didn’t change and marks what disappeared. This is the longest part of the function, and it touches copy, lookup, removal and sorting at once.

CULL

lSortOrder *order = lParseSortOrderVarArg(LR_Type, "%I+", LR_host);
...
if (lr_list == nullptr) {
   lr_list = lCopyList("", tmp_lr_list);
   lFreeElem(&last_lr);
   lSortList(tmp_lr_list, order);
   lSetList(report, REP_list, tmp_lr_list);
} else {
   lListElem *lr;

   for_each_rw(lr, lr_list) {
      const void *iterator = nullptr;
      const char *hostname = lGetHost(lr, LR_host);
      const char *name = lGetString(lr, LR_name);
      const char *value = lGetString(lr, LR_value);
      lListElem *ep, *next_ep;
      bool found = false;

      next_ep = lGetElemStrFirstRW(tmp_lr_list, LR_name, name, &iterator);
      while ((ep = next_ep)) {
         next_ep = lGetElemStrNextRW(tmp_lr_list, LR_name, name, &iterator);
         if (sge_hostcmp(lGetHost(ep, LR_host), hostname) == 0) {
            found = true;
            if (!send_all && sge_strnullcmp(lGetString(ep, LR_value), value) == 0) {
               lRemoveElem(tmp_lr_list, &ep);
            } else {
               lSetString(lr, LR_value, nullptr);
            }
            break;
         }
      }

      if (!found) {
         lListElem *del_report = lCopyElem(lr);
         lSetUlong(del_report, LR_is_static, 2);
         lAppendElem(tmp_lr_list, del_report);
      }
   }

   lSortList(tmp_lr_list, order);
   lSetList(report, REP_list, tmp_lr_list);
   lFreeElem(&last_lr);
   last_lr = lCopyElem(report);
}
lFreeSortOrder(&order);

TOM

if (lr_list == nullptr) {
   lr_list = tmp_lr_list->clone("").release();
   ocs::tom::ElementPtr<ocs::tom::REP>::from_typed(std::exchange(last_lr, nullptr)).reset();
   tmp_lr_list->sort<ocs::tom::asc<LR_host>>();
   report->set<REP_list>(std::move(tmp_lr_list));
} else {
   for (const auto lr : ocs::tom::List<ocs::tom::LR>(lr_list)) {
      const char *hostname = lr.get<LR_host>();
      const char *name = lr.get<LR_name>();
      const char *value = lr.get<LR_value>();
      bool found = false;

      for (const auto ep : tmp_lr_list->find_all<LR_name>(name)) {
         if (sge_hostcmp(ep.get<LR_host>(), hostname) == 0) {
            found = true;
            if (!send_all && sge_strnullcmp(ep.get<LR_value>(), value) == 0) {
               tmp_lr_list->erase(ep);
            } else {
               lr.set<LR_value>(nullptr);
            }
            break;
         }
      }

      if (!found) {
         auto del_report = lr.clone();
         del_report->set<LR_is_static>(2);
         tmp_lr_list->push_back(std::move(del_report));
      }
   }

   tmp_lr_list->sort<ocs::tom::asc<LR_host>>();
   report->set<REP_list>(std::move(tmp_lr_list));
   ocs::tom::ElementPtr<ocs::tom::REP>::from_typed(std::exchange(last_lr, nullptr)).reset();
   last_lr = report->clone().release();
}

What changed

  • The sort order is no longer a format string parsed at run time ("%I+" — the I is the field’s type letter, and a wrong letter is a run-time error). sort<asc<LR_host>>() is checked by the compiler, needs no lFreeSortOrder() and, measured, sorts several times faster, because the comparison is generated for this field at compile time.
  • The lookup loop loses its bookkeeping: no iterator variable, no next_ep to keep a step ahead. find_all<LR_name>(name) is a range over every element with that key, using the same hash table as lGetElemStrFirst. The erase() inside that range is safe only because the break right after it leaves the range; without the break, it would be the use-after-erase of step 4.
  • Copies are explicit. lCopyList/lCopyElem become clone(), and a copy is always an owner. clone("") names the copy as lCopyList("", …) did; clone() without a name keeps the name of the original.
  • The statics stay raw. lr_list and last_lr live for the whole process, so they stay lList * and lListElem * (step 2). The loop views lr_list through a checked List<LR>; the old last_lr is handed to a temporary owner with from_typed() and freed by its reset(), and the new copy is release()d into the static. That is the transition pattern for every static holder.

Calls in this step

CULLTOM
lParseSortOrderVarArg(T_Type, fmt, …), lParseSortOrder, lCreateSortOrder, lAddSortCriteriasort_order<asc<F>, desc<G>, …>() — a SortOrder<T>
lSortList(lp, order)list.sort(order)
lPSortList(lp, fmt, …)list.sort<asc<F>, desc<G>>()
lFreeSortOrder(&order)nothing
lCopyList(name, lp)list.clone(name); clone() keeps the name
lCopyListHash(name, lp, false)raw clone(lp, Hashing::Off); the typed clone() always hashes
lCopyElem(ep), lCopyElemHashe.clone()
lGetElemStr, lGetElemUlong, lGetElemUlong64, lGetElemHost and their RW formslist.find_first<F>(key)
lGetElemCaseStrlist.find_first_nocase<F>(key)
lGetElemStrLikelist.find_first_like<F>(pattern)
lDelElemStr, lDelElemHost, lDelElemUlong, lDelElemUlong64list.erase<F>(key) — 0 or 1

Pitfalls

  • lDelElemStr() freed a list that became empty; erase<F>() keeps it. Code that took a null list for “no entries” asks empty().
  • clone() keeps nullptr → nullptr and empty → empty, as lCopyList() did: cloning an empty handle gives an empty owner, not an empty list.

  1. Over the wire

Where we are

The execd packs its list of reports into a buffer and sends it; the qmaster’s listener unpacks it.

CULL

// execd, ocs::gdi::ClientExecd::report_list_send()
if ((ret = init_packbuffer(&pb, 1024)) == PACK_SUCCESS) {
   ret = cull_pack_list(&pb, rlp);
}

// qmaster, do_report_request()
lList *rep = nullptr;
if (cull_unpack_list(&(aMsg->buf), &rep)) {
   ERROR(SFNMAX, MSG_CULL_FAILEDINCULLUNPACKLISTREPORT);
   DRETURN_VOID;
}

TOM

// execd
if ((ret = ocs::tom::try_init_buffer(&pb, 1024)) == PACK_SUCCESS) {
   try {
      rlp.pack(pb);
   } catch (const ocs::tom::PackException &e) {
      // the code cull_pack_list() returned
      ret = e.code();
   }
}

// qmaster
ocs::tom::ListPtr<ocs::tom::REP> rep;
try {
   rep = ocs::tom::ListPtr<ocs::tom::REP>::unpack(aMsg->buf);
} catch (const ocs::tom::PackException &) {
   // the bytes cut off or no memory, where cull_unpack_list() returned an error
   ERROR(SFNMAX, MSG_QMASTER_UNPACKREPORTFAILED);
   DRETURN_VOID;
} catch (const ocs::tom::FieldException &) {
   // a list of another type than reports: refused here, so a worker thread never meets it
   ERROR(SFNMAX, MSG_QMASTER_UNPACKREPORTFAILED);
   DRETURN_VOID;
}

What changed

  • Packing is a member. rlp.pack(pb) on a ConstList<REP>, ListPtr<REP>::unpack(pb) on the receiving side. The same exists for elements, conditions and selections.
  • Errors are exceptions. Every failure throws PackException, and e.code() is the old PACK_* code, so a function whose callers expect a return code catches it and returns the code — as report_list_send() does.
  • The receiver checks the type. cull_unpack_list() gave you whatever list was in the buffer. The typed unpack() throws WrongType for a list of another type, so the listener refuses it before a worker thread ever sees it. That’s a new check on an old path, and it’s caught right there — see step 14 for why that matters.

Calls in this step

CULLTOM
init_packbuffer, clear_packbufferPackBuffer(with_sender, initial_size) and its destructor; on a raw sge_pack_buffer: try_init_buffer()/init_buffer(), clear_buffer()
init_packbuffer_from_bufferPackBuffer::reading(bytes, size, with_sender)
cull_pack_list, cull_pack_list_partiallist.pack(pb), list.pack(pb, what)
cull_unpack_list, cull_unpack_list_partialListPtr<T>::unpack(pb, flags); type known only at run time: unpack_raw_list(pb)
cull_pack_elem, cull_pack_elem_partiale.pack(pb), e.pack(pb, what)
cull_unpack_elem, cull_unpack_elem_partialElementPtr<T>::unpack(pb, flags); raw unpack_raw_elem(pb, descr)
cull_pack_enum, cull_unpack_enumwhat.pack(pb), What<T>::unpack(pb)
cull_pack_cond, cull_unpack_condwhere.pack(pb), Where<T>::unpack(pb)
cull_pack_descr, cull_pack_enum_as_descrpack_descr, pack_what_as_descr (pack core)
peek at the next typenext_list_is<T>(pb), next_elem_is<T>(pb)
packint, packint64, packdouble, packstr, packbufput_uint32, put_uint64, put_double, put_str, put_buf
unpackint, unpackint64, unpackdouble, unpackstr, unpackbufget_uint32, get_uint64, get_double, get_str, get_buf
repackintreput_uint32
pb_used, pb_filled, pb_unusedbuffer_used, buffer_filled, …
cull_pack_strerror, pb_are_equivalent, cull_reresolve_check_userpack_error_text, buffers_equal, check_sender
getByteArray, setByteArraybytes_to_hex() and its reverse in the pack core

Pitfalls

  • PackBuffer and PackBuffer::reading() default to no sender information; init_packbuffer() defaulted to with_auth_info = true. A buffer that goes to another component needs PackBuffer(true).
  • A type with an Int32 or Int64 field can’t be packed: pack() doesn’t compile for it. Pack it with a selection that leaves those fields out.

  1. qmaster files the report under the host

Where we are

A worker thread takes the reports, and for each load report sge_c_report() calls sge_update_load_values() in daemons/qmaster/sge_host_qmaster.cc. The first thing it needs is the host.

CULL

const lList *master_ehost_list = *ocs::DataStore::get_master_list(SGE_TYPE_EXECHOST);
...
host_ep = lGetElemHostRW(master_ehost_list, EH_name, rhost);
if (host_ep == nullptr) {
   /* report from unknown host arrived, ignore it */
   DRETURN_VOID;
}
...
for_each_rw(ep, lp) {
   const char *name = lGetString(ep, LR_name);
   const char *value = lGetString(ep, LR_value);
   const char *host = lGetHost(ep, LR_host);
   uint32_t global = lGetUlong(ep, LR_global);
   uint32_t is_static = lGetUlong(ep, LR_is_static);
   ...

TOM

const auto master_ehost_list = ocs::DataStore::master_list_rw<SGE_TYPE_EXECHOST>();
...
ocs::tom::Element<ocs::tom::EH> host_ep_eh = master_ehost_list.find_first<EH_name>(ocs::tom::Host(rhost));
if (host_ep_eh == nullptr) {
   /* report from unknown host arrived, ignore it */
   DRETURN_VOID;
}
...
for (const auto ep : lp) {
   const char *name = ep.get<LR_name>();
   const char *value = ep.get<LR_value>();
   const char *host = ep.get<LR_host>();
   uint32_t global = ep.get<LR_global>();
   uint32_t is_static = ep.get<LR_is_static>();
   ...

What changed

  • The master list is typed by its slot. master_list_rw<SGE_TYPE_EXECHOST>() returns a List<EH>; the data store knows which type each slot holds. A host lookup on the job list doesn’t compile any more.
  • The key type says how to compare. find_first<EH_name>(Host(rhost)) — the key is a Host, and the lookup compares like sge_hostcmp(), as lGetElemHost did. A plain string key on a host field doesn’t compile.
  • const char *host = ep.get<LR_host>() uses the implicit conversion of Host; the variable keeps its old type, and the code below it stays as it was.

Calls in this step

CULLTOM
*ocs::DataStore::get_master_list(SGE_TYPE_X)ocs::DataStore::master_list<SGE_TYPE_X>() — a typed ConstList
*ocs::DataStore::get_master_list_rw(SGE_TYPE_X)ocs::DataStore::master_list_rw<SGE_TYPE_X>() — a typed List
lGetElemHost(lp, F, name), lGetElemHostRWlist.find_first<F>(Host(name))

  1. Merging the values into the host

Where we are

For every value of the report, the qmaster updates the host’s EH_load_list, a list of HL elements keyed by name: replace a value, add a new one, or remove one the execd marked as deleted (LR_is_static == 2, from step 6).

CULL

if (is_static == 2) {
   /* remove old load value */
   lep = lGetSubStrRW(*hepp, HL_name, name, EH_load_list);

   lRemoveElem(lGetListRW(*hepp, EH_load_list), &lep);
} else {
   /* add a new load value */
   lep = lGetSubStrRW(*hepp, HL_name, name, EH_load_list);
   if (lep == nullptr) {
      lep = lAddSubStr(*hepp, HL_name, name, EH_load_list, HL_Type);
      ...
   }
   ...
   /* copy value */
   lSetString(lep, HL_value, value);
   lSetUlong64(lep, HL_last_update, now);
   lSetBool(lep, HL_is_static, is_static);
}

TOM

if (is_static == 2) {
   /* remove old load value */
   const ocs::tom::Element<ocs::tom::HL> lep = hepp->find_first_in_rw<EH_load_list, HL_name>(name);

   if (lep) {
      hepp->get<EH_load_list>().erase(lep);
   }
} else {
   /* add a new load value */
   ocs::tom::Element<ocs::tom::HL> lep = hepp->find_first_in_rw<EH_load_list, HL_name>(name);
   if (lep == nullptr) {
      lep = hepp->emplace_back_in<EH_load_list, HL_name>(name);
      ...
   }
   ...
   /* copy value */
   lep.set<HL_value>(value);
   lep.set<HL_last_update>(now);
   lep.set<HL_is_static>(is_static);
}

What changed

  • Field and key in one call, both checked. lGetSubStrRW(*hepp, HL_name, name, EH_load_list) named the key field before the list field, and nothing checked that HL_name is a field of what EH_load_list holds. find_first_in_rw<EH_load_list, HL_name>(name) names the list field first, and a key field that isn’t a field of HL doesn’t compile.
  • lAddSubStr() lost its type argument. HL_Type was the caller’s promise of what the list holds. Now the model says it (step 10), and emplace_back_in<EH_load_list, HL_name>(name) creates the list if it’s missing, as lAddSubStr() did.
  • A null element is no longer removed silently. lRemoveElem(list, &lep) with lep == nullptr did nothing. erase() takes a handle that must be in the list, so the code now says if (lep) — the case was always there, now it is visible.

Order made visible

A strict contract also shows where the order of two steps matters. A few lines above this block, the CULL version stored the full topology string of a topology value on the host, and only then looked the host of that value up:

// CULL: *hepp is still the host of the previous value, or nullptr for the first one
lSetString(*hepp, EH_internal_topology, topology.to_string(true, true, true, false, false, false).c_str());
...
/* get the new host */
*hepp = lGetElemHostRW(master_ehost_list, EH_name, host);

In the usual case, a report carries the values of one host, and the order makes no difference. It only matters in a report that switches hosts, or for the very first value, where CULL’s soft return value of −1 let the call pass without a trace. With the member form the order can’t stay implicit: a set on an empty handle throws EmptyHandle, so the conversion made the question visible and the code now says what it means. It keeps the string until the host is known and stores it then:

// the full topology string goes to the host this load value belongs to (CS-3192)
if (internal_topology) {
   hepp->set<EH_internal_topology>(internal_topology->c_str());
}

Calls in this step

CULLTOM
lGetSubStr, lGetSubHost, lGetSubUlong, lGetSubUlong64e.find_first_in<LF, F>(key)
the same with RWe.find_first_in_rw<LF, F>(key)
lAddSubStr, lAddSubHost, lAddSubUlong, lAddSubUlong64e.emplace_back_in<LF, F>(key), or e.get_or_create<LF>().emplace_back<F>(key)
lDelSubStr, lDelSubUlong, lDelSubUlong64e.erase_in<LF, F>(key) — frees an emptied list, as lDelSubStr() did; e.get<LF>().erase<F>(key) keeps it
cull_compress_definition_listlist.keep_last<F>()
cull_merge_definition_listdst.merge_by_key<Key, Value>(src)
attr_mod_sub_listobj.modify_sublist<ListF, SubKeyF>(request, mode, differs, report); in the qmaster wrapped by attr_mod_sub_list<ListF, SubKeyF>()

Pitfalls

  • The sub-list forms (find_first_in, emplace_back_in, erase_in) find nothing on an empty handle and on a field without a list, as their CULL ancestors did. The chained form e.get<LF>().find_first<F>(key) gives the same for a missing list, but throws EmptyHandle when e itself is empty. Pick the one whose behaviour the old code had.

  1. Why REP_list stays ANY and EH_load_list is HL

Where we are

Two list fields have appeared on the journey. EH_load_list always holds HL elements. REP_list holds load values in a load report — and configuration versions in a configuration report, job reports in a job report, and so on, depending on REP_type.

CULL

CULL had a place for the element type in the field definition, and for these two fields it said:

EH_load_list   lListT   sub-type HL
REP_list       lListT   sub-type ANY

But nothing used it at compile time. lGetList(report, REP_list) and lGetList(host, EH_load_list) both returned const lList *, and every caller decided for itself what it expected to find.

TOM

For EH_load_list the generator writes SubType<EH_load_list> (step 1), and the typed handles use it: host.get<EH_load_list>() returns a List<HL>, set<EH_load_list>() takes only a ListPtr<HL>. For REP_list there is no SubType: get<REP_list>() hands out a raw list handle, and set<REP_list>() takes an owner of any type. The code that knows what the report holds says so — here in sge_c_report():

// REP_list names no sub-type in the model; a load report holds LR elements, unpacked with their
// descriptor, from_typed keeps the old tolerance
sge_update_load_values(rhost, nullptr, ocs::tom::List<ocs::tom::LR>::from_typed(
                          report.get<REP_list>()), packet->gdi_session);

Where the type is not guaranteed, report.get_as<REP_list, ocs::tom::LR>() gives the same typed view after a run-time check, and throws WrongType otherwise.

What changed

Converting the code made it obvious how often the model had said nothing where everyone knew the answer. 55 list and object fields of the model named no sub-type although they always hold one type — the 48 attribute lists of a cluster queue, the checkpointing object of a job, the filters of a resource quota rule, the event client of an event client request. The type was “known” from code somewhere else. Naming it in the model made get<CQ_seq_no>() return a typed list, let the compiler reject a wrong element type, and let the JSON spooler drop its fallbacks.

Twelve fields stay generic on purpose: the report list, the value of a parsed command-line switch, XML elements, the payload of events and GDI requests, and a few more. And one of them is a lesson. JG_queue always holds a queue instance — but a reduced one, carrying only what the execd needs. Naming QU as its sub-type made the execd’s structure check of every incoming job compare that reduced queue with the full queue descriptor, and fail. So it stays generic. A type is more than a name; it is a layout.

Calls in this step

CULLTOM
lGetList, lGetObject on a field without a sub-typee.get<F>() — a raw handle (ConstRawList, RawList, ConstRawElement, RawElement)
the same, when the caller knows the typee.get_as<F, U>() — checked, WrongType for another type
lSetList, lSetObject on such a fielde.set<F>(std::move(owner)) — an owner of any type
lXchgList on such a fielde.exchange<F>(std::move(owner)) — the old content as RawListPtr
a raw owner becomes typedadopt<U>(std::move(raw_owner)) — checked; on failure the raw owner keeps it

Pitfalls

  • A field with a sub-type keeps its strict setter: a ListPtr of another type doesn’t compile there, and get_as doesn’t exist for it.
  • ElementPtr<T>(raw.release()) leaks the element when the checked constructor throws. Use adopt<T>().

  1. Asking for hosts: a reduced copy

Where we are

The load values are filed. Now someone wants to read them — qquota, for example, which shows how much of a resource quota is used and needs, per host, the name, the load list, the consumables and their utilization. Nothing else of the host. Its model on the qmaster side selects exactly that from the master list: which hosts (a condition, CULL’s where) and which fields of them (a selection, CULL’s what).

CULL

From libs/procedure/qquota/ocs_QQuotaModelBase.cc and ocs_QQuotaModelServer.cc:

lEnumeration *ocs::QQuotaModelBase::get_host_what() {
   return lWhat("%T(%I %I %I %I)", EH_Type, EH_name, EH_load_list, EH_consumable_config_list, EH_resource_utilization);
}

lCondition *ocs::QQuotaModelBase::get_host_where(const lList *host_list) {
   lCondition *where = nullptr;

   for_each_ep_lv(ep, host_list) {
      lCondition *nw = lWhere("%T(%I h= %s)", EH_Type, EH_name, lGetString(ep, ST_name));
      if (!where) {
         where = nw;
      } else {
         where = lOrWhere(where, nw);
      }
   }
   if (where != nullptr) {
      const lCondition *nw = lWhere("%T(%I == %s)", EH_Type, EH_name, SGE_GLOBAL_NAME);
      where = lOrWhere(where, nw);
   }
   lCondition *nw = lWhere("%T(%I != %s)", EH_Type, EH_name, SGE_TEMPLATE_NAME);
   if (where) {
      where = lAndWhere(where, nw);
   } else {
      where = nw;
   }
   return where;
}

// in the server model
lEnumeration *exec_host_what = get_host_what();
lCondition *exec_host_where = get_host_where(host_name_list);
exec_host_list_ = lSelect("", master_exec_host_list, exec_host_where, exec_host_what);
lFreeWhat(&exec_host_what);
lFreeWhere(&exec_host_where);

Two small languages hide in the strings. "%T(%I %I %I %I)" says: a selection on the type given by the first argument, with the four fields that follow. "%T(%I h= %s)" says: the field compared as a host name (h=, which is sge_hostcmp()) with a string. The arguments come through varargs. If a field doesn’t belong to EH, if %s meets a number, or if h= meets a field that isn’t a host — all of that compiles, and you find out when the line runs.

TOM

ocs::tom::What<ocs::tom::EH> ocs::QQuotaModelBase::get_host_what() {
   return ocs::tom::what<EH_name, EH_load_list, EH_consumable_config_list, EH_resource_utilization>();
}

ocs::tom::Where<ocs::tom::EH> ocs::QQuotaModelBase::get_host_where(const ocs::tom::ConstList<ocs::tom::ST> host_list) {
   DENTER(TOP_LAYER);
   ocs::tom::Where<ocs::tom::EH> where;

   for (const auto ep : host_list) {
      where |= ocs::tom::field<EH_name>().same_host(ep.get<ST_name>());
   }
   if (where) {
      where |= ocs::tom::field<EH_name>() == SGE_GLOBAL_NAME;
   }
   where &= ocs::tom::field<EH_name>() != SGE_TEMPLATE_NAME;
   DRETURN(where);
}

// in the server model
const auto master_exec_host_list = ocs::DataStore::master_list<SGE_TYPE_EXECHOST>();
exec_host_list_ = ocs_procedure_select(master_exec_host_list, get_host_where(host_name_list), get_host_what());

What changed

  • The strings are gone. what<EH_name, EH_load_list, …>() takes the fields as template arguments; a field of another type doesn’t compile. field<EH_name>() == SGE_GLOBAL_NAME is a C++ expression; comparing a number field with a string doesn’t compile either (field<US_fshare>() == "10" is one of the compile-fail tests).
  • The operators are named. h= became same_host(), c= equals_nocase(), p= like(), m= has_all_bits(), -> any(). ==, !=, <, >, <=, >= stay operators; &&, || and ! combine conditions like lAndWhere(), lOrWhere() and the ! in the format string.
  • Collecting conditions got simple. The CULL loop had to special-case the first condition, because lOrWhere(nullptr, nw) is not “just nw“. where |= … and where &= … leave an empty side out, so the loop starts from an empty Where and the special cases disappear.
  • Nothing to free. What and Where are owners; lFreeWhat() and lFreeWhere() happen in their destructors.
  • No match gives an empty list. lSelect() returned nullptr when nothing matched; the typed select() returns an empty list. The procedure models were written against the old contract, so ocs_procedure_select() keeps it — it calls list.select(where, what, "") and turns an empty result into an empty handle. Code that tested for nullptr to mean “no hosts” must either keep a wrapper like this or test empty().

The reduced element

The result of a selection with a what is a list of reduced elements: only the four selected fields are present. In TOM a reduced layout keeps the full length of the type and marks the fields it leaves out as absent. Two consequences:

  • Reading a field that wasn’t selected — host.get<EH_processors>() on an element of exec_host_list_ — throws FieldException with reason AbsentField. In CULL, lGetUlong() on a missing field printed an error and returned 0, and the code went on with a host that had zero processors. Code that may see reduced elements asks has<F>() first.
  • The checked constructor of a handle looks at the first field of the descriptor, so it accepts reduced elements of its type. from_typed() skips even that check, and the converted code uses it where the source guarantees the type. The scheduler’s host list is such a place: host_list_locate() is a raw lookup in a list that holds nothing but hosts, so sort_host_list() wraps its result without a check:
const auto global = ocs::tom::ConstElement<ocs::tom::EH>::from_typed(host_list_locate(hl, SGE_GLOBAL_NAME));

The mirror: subscribing to part of a type

The same selections decide what a component receives through events. The scheduler subscribes to hosts with a condition and a field list that is built at run time:

// CULL
where_what->where_host = lWhere("%T(!(%Ic=%s))", EH_Type, EH_name, SGE_TEMPLATE_NAME);
where_what->what_host = lIntVector2What(EH_Type, eh_nm);

// TOM
where_what->where_host = !ocs::tom::field<EH_name>().equals_nocase(SGE_TEMPLATE_NAME);
where_what->what_host = ocs::tom::what<ocs::tom::EH>(eh_nm);

what<EH>(eh_nm) takes field numbers from an array and checks them at run time: a field of another type throws ForeignField. The qmaster’s own mirror listener needs only host names, and a nested selection on user sets:

// CULL
lEnumeration *eh_what = lWhat("%T(%I)", EH_Type, EH_name);
sge_mirror_subscribe(evc, SGE_TYPE_EXECHOST, nullptr, nullptr, nullptr, nullptr, eh_what);
lFreeWhat(&eh_what);
...
lEnumeration *us_what = lWhat("%T(%I%I->(%I))", US_Type, US_name, US_entries, UE_name);

// TOM
const auto eh_what = ocs::tom::what<EH_name>();
sge_mirror_subscribe(evc, SGE_TYPE_EXECHOST, nullptr, nullptr, nullptr, nullptr, eh_what.get());
...
const auto us_what = ocs::tom::what<US_name>().with<US_entries>(ocs::tom::what<UE_name>());

%I->(%I) — “of the list field US_entries, only UE_name” — becomes with<US_entries>(what<UE_name>()), and with() only accepts a list or object field and a selection of its sub-type. get() hands the raw lEnumeration * to a function that hasn’t been converted yet.

Calls in this step

CULLTOM
lWhat("%T(%I %I)", T_Type, A, B)what<A, B>()
lWhat("%T(ALL)", T_Type), lWhatAllwhat_all<T>()
lWhat("%T(%I%I->(%I))", …)what<A>().with<L>(what<X>())
lIntVector2What(T_Type, fields)what<T>(fields) — checked at run time, no NoName terminator
lMergeWhatstd::move(a).merge(std::move(b))
lWhatSetSubWhatstd::move(what).nest<L>(sub)
lFreeWhat(&w), lCopyWhatnothing; raw clone(what)
lWhere("%T(%I == %s)", …), !=, <, >, <=, >=field<F>() == v, …
h= / c= / p= / m=same_host() / equals_nocase() / like() / has_all_bits()
lWhere("%T(%I -> %T(…))", …)field<L>().any(condition on the sub-type)
lAndWhere, lOrWhere, !&&, ||, ! — operands taken over; collecting: &=, |=
lFreeWhere(&c), lCopyWherenothing; raw clone(cond)
lSelect(name, lp, where, what)list.select(where, what, name), select(what), select(where) — empty list for no match
lSelect, lSelectHashPack with the old contractselect_as(name, lp, where, what, hashing) — no list for no match
lSelectHashPack into a bufferselect_pack(pb, name, lp, where, what)
lSelectDPack, lSelectElemDPackselect_into_descr(…), select_elem_into_descr(…)
lSelectElemPacke.select(what), e.select(where, what); old contract select_elem_as(…)
lSelectDestroy(lp, where) — keeps the matcheslist.remove_if(!std::move(where))
lFindFirstRW(lp, where), lFindLastRWlist.find_if(where), list.find_last_if(where)
lFindNextRW, lFindPrevRWe.next_if(where), e.prev_if(where)
lCompare(ep, where)e.matches(where)
lReduceDescr, lGetReducedDescr, lPartialDescrlayout<F...>(), ListPtr<T>::create(name, what); the descriptor work is internal to the list core
lWhereToElem, lWhatToElem, lWhereFromElem, lWhatFromElemocs_where_to_elem(), ocs_what_to_elem(), ocs_where_from_elem(), ocs_what_from_elem() in sgeobj/sge_pack.h
a condition built at run timewhere_compare(descr, nm, CompareOp::…, v), what_of(descr, fields)
raw condition or selection becomes typedadopt<T>(std::move(raw)) — checked
lWriteWhatTo, lWriteWhereTowhat.print(fp), where.print(fp)

Pitfalls

  • what<A, B>() with a field of another type is a compile error; what<T>(fields) from a run-time array throws ForeignField instead.
  • with() on what_all<T>() throws ForeignField: “all fields” has no single field to nest under. with() and nest() are rvalue members: call them on a temporary or on std::move(what).
  • &&, || and ! throw for an empty operand; only |= and &= leave an empty side out. Build conditions in a loop with |=/&=, as above.
  • field<F>() == "name" on a host field compares byte-wise, as %I == %s did. Use same_host() where you mean host names.

  1. Splitting the queues by state

Where we are

Before the scheduler places a job, it takes out the queues that can’t take one: suspended, suspended by calendar, disabled by calendar, suspended by a subordinate. Their state is a bit field, so the condition tests bits.

CULL

From sge_split_suspended() in libs/sched/sge_select_queue.cc:

lCondition *where;
int ret;
lList *lp = nullptr;
...
where = lWhere("%T(!(%I m= %u) && !(%I m= %u) && !(%I m= %u) && !(%I m= %u))",
   lGetListDescr(*queue_list),
      QU_state, QI_SUSPENDED,
      QU_state, QI_CAL_SUSPENDED,
      QU_state, QI_CAL_DISABLED,
      QU_state, QI_SUSPENDED_ON_SUBORDINATE);

ret = lSplit(queue_list, &lp, "full queues", where);
lFreeWhere(&where);

if (lp != nullptr) {
   ...
   if (*suspended == nullptr) {
      *suspended = lp;
   } else {
      lAddList(*suspended, &lp);
   }
}

m= is “mask”: true if all bits of the mask are set — with one bit per test, as here, the same as “the bit is set”. Note the type: lGetListDescr(*queue_list) — the descriptor is taken from the list at run time, because the queue list in the scheduler is a reduced one.

TOM

int sge_split_suspended(const bool monitor_next_run, ocs::tom::ListPtr<ocs::tom::QU> &queue_list,
                        ocs::tom::ListPtr<ocs::tom::QU> &suspended) {
   ...
   auto lp = split_queues(queue_list, !ocs::tom::field<QU_state>().has_all_bits(QI_SUSPENDED) &&
                                      !ocs::tom::field<QU_state>().has_all_bits(QI_CAL_SUSPENDED) &&
                                      !ocs::tom::field<QU_state>().has_all_bits(QI_CAL_DISABLED) &&
                                      !ocs::tom::field<QU_state>().has_all_bits(QI_SUSPENDED_ON_SUBORDINATE));

   if (lp != nullptr) {
      ...
      add_split_queues(suspended, std::move(lp));
   }
   ...
}

static ocs::tom::ListPtr<ocs::tom::QU>
split_queues(ocs::tom::ListPtr<ocs::tom::QU> &queue_list, const ocs::tom::Where<ocs::tom::QU> &where) {
   ...
   auto taken = queue_list->split_off(where, "full queues");
   if (queue_list != nullptr && queue_list->empty()) {
      queue_list.reset();
   }
   ...
}

static void
add_split_queues(ocs::tom::ListPtr<ocs::tom::QU> &target, ocs::tom::ListPtr<ocs::tom::QU> &&queues) {
   ...
   if (target == nullptr) {
      target = std::move(queues);
   } else {
      target->splice(std::move(queues));
   }
   ...
}

What changed

  • The condition is four C++ expressions; there is no format string to keep in step with eight varargs. has_all_bits() is offered only for 32 bit fields.
  • split_off() works like lSplit(): the list keeps the elements that fulfil the condition and the others are returned, in a new list with the layout of the source — reduced, if the source is reduced. The type is QU at compile time; the layout still comes from the list at run time, as lGetListDescr() did.
  • The returned list is an owner, so the split-off queues can’t be lost; lSplit() wrote them through an lList ** that the caller had to free or hand on.
  • The old side effect became explicit. lSplit() freed a source list that became empty, and callers relied on it. split_off() doesn’t, so the helper does it in one visible line.
  • The two helpers exist because a second split, for the disabled queues, does the same; sge_split_suspended() itself shrank to the condition and the messages.

Calls in this step

CULLTOM
lSplit(&lp, &rest, name, where)ListPtr<T> rest = list.split_off(where, name) — keeps the matching ones
lWhere("%T(%I m= %u)", …)field<F>().has_all_bits(mask)
lAddList(lp, &other)list.splice(std::move(other))
lDiffListStrlist.remove_common<F>(other)
lString2List, lString2ListNoneListPtr<T>::from_string<F>(s, delimiters, NoneName::Name / NoneName::Empty)
lGetNumberOfNodes, lGetNumberOfLeafscount_nodes<F>(), count_leaves<F>()

Pitfalls

  • has_all_bits() in a condition is “all bits of the mask”; the element member has_any_bits<F>() — the counterpart of lMatchUlongBitMask() — is “any bit”. For a single bit they agree; for a mask of several, convert each with the one the old code meant.
  • split_off() never frees the source; drop the result to free the split-off elements, free an emptied source where the old code relied on lSplit() doing it.

  1. Ordering the hosts

Where we are

The scheduler offers hosts with less load first. sort_host_list() in libs/sched/sort_hosts.cc computes a value per host from the configured load formula, stores it in EH_sort_value, and sorts by it.

CULL

int sort_host_list(lList *hl, const lList *centry_list) {
   DENTER(TOP_LAYER);
   lListElem *global = host_list_locate(hl, SGE_GLOBAL_NAME);
   const char *load_formula = sconf_get_load_formula();

   for_each_rw_lv(hlp, hl) {
      if (hlp == global) {
         continue;
      }

      /* build complexes for that host */
      double load = scaled_mixed_load(load_formula, global, hlp, centry_list, nullptr);
      lSetDouble(hlp, EH_sort_value, load);
      DPRINTF("%s: %f\n", lGetHost(hlp, EH_name), load);
   }
   sge_free(&load_formula);

   if (lPSortList(hl,"%I+", EH_sort_value)) {
      DRETURN(-1);
   } else {
      DRETURN(0);
   }
}

TOM

int sort_host_list(const ocs::tom::List<ocs::tom::EH> hl, const ocs::tom::ConstList<ocs::tom::CE> centry_list) {
   DENTER(TOP_LAYER);
   const auto global = ocs::tom::ConstElement<ocs::tom::EH>::from_typed(host_list_locate(hl, SGE_GLOBAL_NAME));
   const char *load_formula = sconf_get_load_formula();

   for (const auto hlp : hl) {
      if (hlp == global) {
         continue;
      }

      /* build complexes for that host */
      double load = scaled_mixed_load(load_formula, global, hlp, centry_list, ocs::tom::ConstList<ocs::tom::CE>());
      hlp.set<EH_sort_value>(load);
      DPRINTF("%s: %f\n", hlp.get<EH_name>().c_str(), load);
   }
   sge_free(&load_formula);

   // as lPSortList() did, an absent list is an error
   if (hl == nullptr) {
      DRETURN(-1);
   }
   hl.sort<ocs::tom::asc<EH_sort_value>>();
   DRETURN(0);
}

What changed

  • "%I+" — the letter is the field type, + ascending, - descending — becomes asc<F>/desc<F>; the type is known from the field, and only number, bool, string and host fields compile as sort keys.
  • The return value stays. The typed sort() returns nothing and throws on misuse, so the one case where lPSortList() returned −1 that the scheduler could meet — no list at all — is now an explicit test. The signature of the function didn’t change for its callers.
  • host_list_locate() stays: it treats the global host specially, and it is used all over the scheduler. Its raw result is wrapped with from_typed() (step 11).
  • hlp.get<EH_name>().c_str() — the Host going into DPRINTF‘s varargs (step 3).

Three ways to sort

lPSortList(hl, "%I+", EH_sort_value) is the short form of what step 6 did in two parts — parse an order, sort with it. TOM has all three forms, typed. A fixed order, given inline, from libs/sgeobj/ocs_Job.cc:

// CULL
lPSortList(tmp_list, "%I- %I+ %I+", SGEJ_priority, SGEJ_submission_time, SGEJ_job_number);

// TOM
tmp_list->sort<ocs::tom::desc<SGEJ_priority>, ocs::tom::asc<SGEJ_submission_time>,
               ocs::tom::asc<SGEJ_job_number>>();

An order kept for later use, here to move one host after its load changed, from libs/sched/debit.cc:

// CULL
so = lParseSortOrderVarArg(lGetListDescr(host_list), "%I+", EH_sort_value);
...
lResortElem(so, hep, host_list);
...
lFreeSortOrder(&so);

// TOM
const auto so = ocs::tom::sort_order<ocs::tom::asc<EH_sort_value>>();
...
// lResortElem() did nothing for a host that is not in the list
if (hep) {
   host_list.resort(so, hep);
}

And an order no field expresses — a comparison, like std::sort. CULL had no such form; the old code filled a helper field with the computed key and sorted by it. From the module tests:

jobs->sort([](const ConstElement<JB> a, const ConstElement<JB> b) {
   const std::uint32_t x = a.get<JB_job_number>();
   const std::uint32_t y = b.get<JB_job_number>();
   return x % 10 != y % 10 ? x % 10 < y % 10 : x < y;
});

Calls in this step

CULLTOM
lPSortList(lp, fmt, …)list.sort<asc<F>, desc<G>>()
lParseSortOrderVarArg(T_Type, fmt, …), lParseSortOrder(dp, fmt, …)sort_order<asc<F>, …>()
lSortList(lp, order)list.sort(order)
sort by a computed keylist.sort(less) with a predicate on ConstElement<T>
lSortCompareinternal to the sort core
lInsertSorted(order, ep, lp)list.insert_sorted(order, std::move(ep))
lResortElem(order, ep, lp)list.resort(order, ep)
lFreeSortOrder(&so)nothing
lUniqStr, lUniqHostlist.unique<F>() — sorts by the key and keeps the first of each

Pitfalls

  • Sorting a reduced list by a field the selection left out throws AbsentField; lPSortList() failed with an error message.
  • insert_sorted() and resort() with an empty order throw; resort() with an element of another list throws ForeignList. insert_sorted() needs a list that is already sorted by the same order.
  • The sort is stable and rebuilds the hash tables, like the old one.

  1. When things go wrong

Where we are

Not every report is well-formed, not every host is known, and not every request carries every field. CULL had three ways of reporting trouble: a return value (0/−1, nullptr), the thread-local lerrno, and an answer list. Many callers checked none of them.

The rule

TOM reports misuse with exceptions, and it is precise about which:

ExceptionWhen
ocs::tom::FieldExceptiona misuse of a field or a handle — a logic error, with a reason()
ocs::tom::ListCoreErrora failure of the storage layer — what() says what failed
ocs::tom::PackExceptiona failure of packing — code() is the old PACK_* code

ListCoreError and PackException derive from ocs::RuntimeException. The reasons of a FieldException:

ReasonWhen
NullElement, NullLista free or raw form got nullptr
EmptyHandlea member was called on an empty typed handle
ForeignFieldthe field doesn’t belong to the element’s type
AbsentFieldthe reduced element doesn’t hold the field
WrongTypean element or list of another type than the handle; a raw value type that isn’t the field’s
WrongSubTypea list or object field holds elements of another type than the model names
WrongLayoutan element or list of another layout is added to a list
BoundElementan element to store or append is already in a list or object
ForeignListthe element isn’t in the list the operation names
NullKeya lookup or an add by a nullptr string or host key
NullDescriptorcreate with a null descriptor or an empty layout
OutOfMemorya string could not be copied
DuplicateKey(debug builds) a unique field would hold a value twice

What throws and what doesn’t: the members of the typed handles and the raw accessors throw on every error. The free typed setters on raw pointers keep the old soft behaviour and return −1 — and in a debug build they record each such call with its stack, so a test run lists the code that relies on a soft path. The old-contract selections (select_as and friends) throw nothing of the object model. create() and clone() throw when there is no memory instead of returning nullptr. lerrno is gone.

No new throw where the old code survived

Exceptions are only an improvement if they don’t turn a survivable situation into a dead qmaster. The rule for converting: on a path where the old code survived bad input — client data on a GDI path, a reduced request element — the conversion must not introduce a throw. A modify request for a host carries only the fields the client sent, and the qmaster has always asked before reading:

// CULL
if (lGetPosViaElem(ep, EH_scaling_list, SGE_NO_ABORT) >= 0) {
   attr_mod_sub_list(alpp, new_host, EH_scaling_list, HS_name, ep, cmd,
                     sub_command, SGE_ATTR_LOAD_SCALING, SGE_OBJ_EXECHOST, 0, &changed);

// TOM
if (reduced.has<EH_scaling_list>()) {
   changed = attr_mod_sub_list<EH_scaling_list, HS_name>(alpp, new_eh, reduced, sub_command,
                                                         SGE_ATTR_LOAD_SCALING, SGE_OBJ_EXECHOST).changed;

Where a new check meets data from outside, it is caught at the boundary and answered the old way. That is what the listener in step 7 does with a buffer that holds a list of another type: it logs the same error as before and drops the request, instead of letting a worker thread die on it.

The journey’s failures

SituationCULLTOM
report from an unknown hostlGetElemHostRW() returns nullptrfind_first<EH_name>() returns an empty handle; the code tests it, as before
a value for a host the qmaster doesn’t knownullptr, an INFO messagethe same
bytes cut off on the wirecull_unpack_list() returns an error codePackException, caught in the listener
a list of another type in the bufferaccepted, fails somewhere laterFieldException (WrongType), caught in the listener
a field absent from a reduced hosterror message, 0AbsentField
set on a host that wasn’t looked up yet−1, unnoticed (step 9)EmptyHandle

Pitfalls

  • Every get<F>() on client data needs a decision: was the old read soft (SGE_NO_ABORT, a default) or did it abort? Keep exactly that.
  • A catch (...) around converted code hides programming errors. Catch FieldException only where the old code had a soft path, and say in a comment why.
  • An empty handle is not a value to be tolerated silently. Where empty is a normal case — a lookup that may find nothing, an optional sub-object — test it before the call.

  1. Converting a function, step by step

Where we are

The end of the journey: how execd_add_load_report() got from the CULL version to the one shown in steps 2–6. Its history is a fair picture of how every module went.

The steps

  1. Mechanical rewrite to the free forms (f55276887). A tool built on Clang rewrote every accessor with a constant field: lSetUlong(report, REP_type, …) became ocs::tom::set<REP_type>(report, …), lGetElemStrFirstRW became ocs::tom::find_first_rw<LR_name>. Same arguments, same results, same soft contract; the compiler now checked every field against its value type. This step ran over the whole code base at once.
  2. Handles for local variables (926844133, rules L0 and L1 of the tool). Local lListElem * and lList * variables became non-owning Element<T>/List<T> handles. This function had none the rules applied to, so it is unchanged in that commit.
  3. Owners for local variables (d56d59256, rule L3, step 5). report became an ElementPtr<REP>, and lAppendElem(report_list, std::move(report)) showed the transfer. What L3 couldn’t prove — every path ends in exactly one sink, free or return — it refused.
  4. By hand (cc29847f8). The rest: sge_build_load_report() returns a ListPtr<LR>, the lookup loop became find_all, the parsed sort order became sort<asc<LR_host>>(), and the report went into the still raw report list through a checked List<REP> view.
  5. Member form (17abd6093, 64e2ac05e, 9974926f8). The free forms on handles were deleted, so every remaining call had to become a member; the field without a sub-type went last.

During the transition, the old list library carried overloads that took handles at its sinks — that is how step 5’s lAppendElem(…, std::move(report)) compiled. They are gone with CULL. The rule for converted code is now simple: a function takes and returns TOM handles only, and there is no second overload with the raw signature to keep a caller compiling. Convert the caller.

Compile errors you will meet

The test suite has a directory of code that must not compile, test/libs/tom/compile_fail, 65 files at the time of writing. Each file is one mistake, and together they are a good map of the errors you’ll see during a conversion:

// job_field_on_queue.cc: a job field on a queue
const ocs::tom::Element<ocs::tom::QU> queue{raw};
static_cast<void>(queue.get<JB_job_name>());

// setter_on_const.cc: changing what you may only read
const ocs::tom::ConstElement<ocs::tom::JB> job{raw};
job.set<JB_job_number>(1u);

// free_get_on_handle.cc: the free form on a handle
// the member job.get<JB_job_number>() is the only way on a handle
return ocs::tom::get<JB_job_number>(job);

// sort_foreign_field.cc: a user set field as a criterion for sorting jobs
jobs.sort<ocs::tom::asc<US_name>>();

// what_two_types.cc: a user set field and a job field in one selection
auto what = ocs::tom::what<US_name, JB_job_number>();

The first is the one you’ll see most: the field belongs to another type. The second means the handle you hold is a ConstElement — either the function’s parameter should be Element, or the code shouldn’t write. The third means you called a free form on a handle; write job.get<F>(). In a template where the handle type depends on a template parameter, the member template needs the template keyword: ep.template get<F>().

Tests

Every new or changed TOM function gets a check in the module test of its module. The expectations are fixed values derived from the old behaviour — order, nullptr versus an empty list, messages, return values — never values computed by the code under test. A test that takes its expectation from the new code pins its own regression. For a contract with error reasons, check reason(), not only that something was thrown.

Performance notes for TOM code

TOM is faster than CULL almost everywhere, and the earlier posts have the numbers for the whole qmaster. For the code you write, a few things are worth knowing. The figures are nanoseconds per operation from a single-threaded micro benchmark of the list interface, the same source built against CULL in 9.1 and against TOM in 9.2.0alpha1; they may still change before the first customer shipment.

  • Typed and raw cost the same. Over all operations, the typed form takes 0.49 of the time of 9.1, the raw run-time typed form 0.52. Field access is about a third: get<F>() on a 32 bit field 2.7 ns against 7.7 ns. The type checks are paid at compile time.
  • Except for sorting. sort<asc<F>>() generates the comparison for the field at compile time; the raw form interprets a sort order at run time. Sorting 1000 elements by a 32 bit field: 52 µs typed, 126 µs raw, 734 µs in 9.1. Where you can name the fields, name them.
  • Short lists are searched linearly. A list gets a hash table for a key field only from a minimum length on: 16 elements for string and number keys, 8 for string keys in the scheduler thread, which looks up short lists of complexes, queues and resources over and over. Host keys are hashed from the first element. Below the threshold a lookup compares element by element, and a hit in a short string list costs 48 ns against 29 ns in 9.1, which hashed every list. Adding and removing on short lists is cheaper in turn, because there is no table to maintain.
  • An empty owner costs nothing. Destroying a moved-from ElementPtr or ListPtr makes no call; exchanging a list field costs 2.5 ns.
  • Moving many elements is cheap. splice() of 100 elements is 0.02 of 9.1, split_off() on 1000 elements 0.04. Prefer moving a list to copying it element by element.
  • Packing is still slightly slower than in 9.1 (1.1–1.35 ×); unpacking is faster.

Reference: everything the journey didn’t pass

The journey touched the calls a converting developer meets first. Here is the rest, by area. All names are in ocs::tom::; “raw” marks the run-time typed form for code that is generic over object types.

Run-time typed code

Generic code — spooling walkers, the event master, GDI transport, qconf attribute handling, the Python bridge — knows the type only from the descriptor inside the element. It uses the raw handles ConstRawElement/RawElement, ConstRawList/RawList and the owners RawElementPtr/RawListPtr, names fields as int and states the value type itself: ep.get<std::uint32_t>(nm). A mismatch throws FieldException instead of aborting the process.

CULLTOM
lGetUlong(ep, nm) with nm a variableraw ep.get<std::uint32_t>(nm); V must be exactly the field’s type
lSetString(ep, nm, s) with nm a variableraw ep.set(nm, s) — ep.set(nm, 0) passes an int and throws WrongType on a 32 bit unsigned field; write std::uint32_t{0}
walking ep->descrtype_table(ep.descr()[0].nm) and its fields
lCreateElem(descr), lCreateList(name, descr) at run timeRawElementPtr::create(descr), RawListPtr::create(descr, hashing, name)
lGetPosViaElem(…) >= 0 on a descriptorpresent_pos(descr, nm) >= 0
lIsFreeElem, ep->status == FREE_ELEMis_free(e)
cull_hash_create_hashtablesmake_hashable(raw_list)
cull_hash_new_checklist.add_hash<F>(unique)
cull_hash_*, ocs_cull_hash_* (the hash table itself)internal to the list core; per-thread thresholds set_thread_string_hash_threshold(), set_thread_host_hash_threshold()

Dump, files, debug output

CULLTOM
lDumpElemFp, lDumpListe.dump(fp, indent), list.dump(fp, indent)
lUndumpElemFp, lUndumpListElementPtr<T>::undump(fp), ListPtr<T>::undump(fp, name)
lDumpElem(file, …), lUndumpElem(file, …)dump_elem_to(path, ep, indent), undump_elem_from(path, descr)
lDumpObject, lUndumpObject, lDumpDescr, lUndumpDescrdump_object, undump_object, dump_descr, undump_descr (dump core)
lWriteElemToDisk, lReadElemFromDiske.write_to_disk(prefix, name, obj_name), ElementPtr<T>::read_from_disk(prefix, name, obj_name)
lWriteElemTo, lWriteListTo, lWriteWhereTo, lWriteWhatToe.print(fp), list.print(fp), where.print(fp), what.print(fp); raw write_to(fp, x)
lWriteElemToStr, lWriteWhatToDStringprint_elem(buffer, ep, level), print_what(buffer, what, level) (print core)

Name space and errors

CULLTOM
lerrno, cull_state_get_lerrno, lerrorremoved; ListCoreError::what(), PackException::code()
cull_state_*_name_space, lInitinstall_model() (step 1)
cull_parse.h, cull_lerrno.h, the descriptor helpers of cull_types.hgone with the format strings and the descriptor macros; nothing in module code replaces them

List helpers without a successor

lCreateElemList, lGetElemIndex, lOverrideStrList and lAddSubList have no counterpart. Each is a short loop over emplace_back, a walk, or splice().

Wrapping up

If you came to this post knowing CULL, most of TOM is the same ideas with the guesswork taken out. A descriptor became a type, a field number became a field the compiler knows, an lListElem * became one of three handles that say whether you own, change or only read. The format strings of lWhat(), lWhere() and lPSortList() became C++ expressions. The places where CULL handed ownership over silently now say std::move. And the places where CULL returned −1 and moved on now throw — except where the old code had a good reason to survive, and there the converted code says so.

The load report took fifteen steps from the execd to the scheduler’s host order. Every one of them still does what it did in 9.1. The difference is in what can go wrong without anyone noticing, and the answer for most of it is now: nothing, because it doesn’t compile.

That’s the end of the series. The first post has the numbers, the second the reasons, the third the short tour. The code is in the clusterscheduler repository on GitHub: the library in source/libs/tom, the generated types in source/libs/sgeobj/tom, and the examples of this post in the files named in each step. Every header names the CULL function it replaces in its Doxygen blocks (@see Old form:), so if you hold a CULL call and want its successor, a grep for its name in source/libs/tom is the fastest way there.