- * process it. Check this case and reread the chunk. */
-
- /* for partial chunk the end of it is zeroed, check
- * for index 0 to distinguish it. */
- if ((partial_chunk && rec->lrh_index == 0) ||
- (index == lh_last_idx &&
- lh_last_idx != (loghandle->lgh_last_idx + 1))) {
- /* concurrent llog_add() might add new records
- * while llog_processing, check this is not
- * the case and re-read the current chunk
- * otherwise. */
- int records;
- /* lgh_last_idx could be less then index
- * for catalog, if catalog is wrapped */
- if ((index > loghandle->lgh_last_idx &&
- !(loghandle->lgh_hdr->llh_flags &
- LLOG_F_IS_CAT)) || repeated ||
- (loghandle->lgh_obj != NULL &&
- dt_object_remote(loghandle->lgh_obj)))
- GOTO(out, rc = 0);
- /* <2 records means no more records
- * if the last record we processed was
- * the final one, then the underlying
- * object might have been destroyed yet.
- * we better don't access that.. */
- mutex_lock(&loghandle->lgh_hdr_mutex);
- records = loghandle->lgh_hdr->llh_count;
- mutex_unlock(&loghandle->lgh_hdr_mutex);
- if (records <= 1)
- GOTO(out, rc = 0);
- CDEBUG(D_OTHER, "Re-read last llog buffer for "
- "new records, index %u, last %u\n",
- index, loghandle->lgh_last_idx);
+ * process it. Check this case and reread the chunk.
+ * It is safe to process to lh_last_idx, including
+ * lh_last_idx if it was synced. We can not do <=
+ * comparison, cause for wrapped catalog lgh_last_idx
+ * could be less than index. So we detect last index
+ * for processing as index == lh_last_idx+1. But when
+ * catalog is wrapped and full lgh_last_idx=llh_cat_idx,
+ * the first processing index is llh_cat_idx+1.
+ */
+
+ if ((index == lh_last_idx && synced_idx != index) ||
+ (index == (lh_last_idx + 1) &&
+ !(index == (llh->llh_cat_idx + 1) &&
+ (llh->llh_flags & LLOG_F_IS_CAT))) ||
+ (rec->lrh_index == 0 && !repeated)) {
+