Skip to content

Commit 90563dd

Browse files
houjungithub-actions[bot]jeanbez
authored
Return the same obj_id if the obj is just created or already opened (#254)
* Return the same obj_id if the obj is just created or already opened * Committing clang-format changes * Update doc * Update dependencies-macos.sh --------- Co-authored-by: github-actions <github-actions[bot]@users.noreply.github.com> Co-authored-by: Jean Luca Bez <[email protected]>
1 parent 1653e4f commit 90563dd

File tree

3 files changed

+47
-5
lines changed

3 files changed

+47
-5
lines changed

docs/source/api.rst

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -205,7 +205,8 @@ PDC object APIs
205205
* pdc: PDC class ID, returned from PDCInit
206206
* Output:
207207
* Local object ID
208-
* Open a PDC ID created previously by name.
208+
* Open a PDC ID created previously by name, if an object is just created or already opened,
209+
return the same obj_id. Each open requires a close.
209210
* For developers: see pdc_obj.c. Need to communicate with servers for metadata of the object.
210211
211212
* perr_t PDCobj_close(pdcid_t obj_id)

src/api/pdc_obj/pdc_obj.c

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -535,9 +535,29 @@ PDCobj_open_common(const char *obj_name, pdcid_t pdc, int is_col)
535535
pdcid_t obj_prop;
536536
size_t i;
537537
uint32_t metadata_server_id;
538+
obj_handle * oh;
539+
struct pdc_obj_info * info;
540+
int is_opened = 0;
538541

539542
FUNC_ENTER(NULL);
540543

544+
// Search if the object has already been opened
545+
oh = PDCobj_iter_start(pdc);
546+
while (!PDCobj_iter_null(oh)) {
547+
info = PDCobj_iter_get_info(oh);
548+
if (strcmp(obj_name, info->name) == 0) {
549+
is_opened = 1;
550+
break;
551+
}
552+
oh = PDCobj_iter_next(oh, pdc);
553+
}
554+
555+
if (is_opened) {
556+
ret_value = info->local_id;
557+
PDC_inc_ref(info->local_id);
558+
goto done;
559+
}
560+
541561
p = (struct _pdc_obj_info *)PDC_malloc(sizeof(struct _pdc_obj_info));
542562
if (!p)
543563
PGOTO_ERROR(0, "PDC object memory allocation failed");

src/tests/obj/open_obj.c

Lines changed: 25 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,7 @@ main(int argc, char **argv)
8282
else {
8383
LOG_ERROR("Rank %d Fail to create object!\n", rank);
8484
ret_value = 1;
85+
goto done;
8586
}
8687
// create second object
8788
sprintf(obj_name2, "o2_%d", rank);
@@ -92,30 +93,39 @@ main(int argc, char **argv)
9293
else {
9394
LOG_ERROR("Rank %d Fail to create object!\n", rank);
9495
ret_value = 1;
96+
goto done;
9597
}
9698

9799
// open first object twice
98-
open11 = PDCobj_open(obj_name1, pdc);
100+
open11 = PDCobj_open(obj_name1, cont);
99101
if (open11 == 0) {
100102
LOG_ERROR("Rank %d Fail to open object o1\n", rank);
101103
ret_value = 1;
104+
goto done;
102105
}
103106
else {
104107
LOG_INFO("Rank %d Open object o1\n", rank);
105108
}
106-
open12 = PDCobj_open(obj_name1, pdc);
109+
open12 = PDCobj_open(obj_name1, cont);
107110
if (open12 == 0) {
108111
LOG_ERROR("Rank %d Fail to open object o1\n", rank);
109112
ret_value = 1;
113+
goto done;
114+
}
115+
else if (open12 != open11) {
116+
LOG_ERROR("Rank %d opened object o1 with different ID %llu / %llu\n", rank, open12, open11);
117+
ret_value = 1;
118+
goto done;
110119
}
111120
else {
112-
LOG_INFO("Rank %d Open object o1\n", rank);
121+
LOG_INFO("Rank %d Re-open object o1\n", rank);
113122
}
114123
// open second object once
115-
open21 = PDCobj_open(obj_name2, pdc);
124+
open21 = PDCobj_open(obj_name2, cont);
116125
if (open21 == 0) {
117126
LOG_ERROR("Rank %d Fail to open object o2\n", rank);
118127
ret_value = 1;
128+
goto done;
119129
}
120130
else {
121131
LOG_INFO("Rank %d Open object o2\n", rank);
@@ -124,34 +134,39 @@ main(int argc, char **argv)
124134
if (PDCobj_close(obj1) < 0) {
125135
LOG_ERROR("Rank %d Fail to close object o1\n", rank);
126136
ret_value = 1;
137+
goto done;
127138
}
128139
else {
129140
LOG_INFO("Rank %d Successfully closed object o1\n", rank);
130141
}
131142
if (PDCobj_close(open11) < 0) {
132143
LOG_ERROR("Rank %d Fail to close object open11\n", rank);
133144
ret_value = 1;
145+
goto done;
134146
}
135147
else {
136148
LOG_INFO("Rank %d Successfully closed object open11\n", rank);
137149
}
138150
if (PDCobj_close(open12) < 0) {
139151
LOG_ERROR("Rank %d Fail to close object open12\n", rank);
140152
ret_value = 1;
153+
goto done;
141154
}
142155
else {
143156
LOG_INFO("Rank %d Successfully closed object open12\n", rank);
144157
}
145158
if (PDCobj_close(obj2) < 0) {
146159
LOG_ERROR("Rank %d Fail to close object o2\n", rank);
147160
ret_value = 1;
161+
goto done;
148162
}
149163
else {
150164
LOG_INFO("Rank %d Successfully closed object o2\n", rank);
151165
}
152166
if (PDCobj_close(open21) < 0) {
153167
LOG_ERROR("Rank %d Fail to close object open21\n", rank);
154168
ret_value = 1;
169+
goto done;
155170
}
156171
else {
157172
LOG_INFO("Rank %d Successfully closed object open21\n", rank);
@@ -160,6 +175,7 @@ main(int argc, char **argv)
160175
if (PDCcont_close(cont) < 0) {
161176
LOG_ERROR("Rank %d Fail to close container c1\n", rank);
162177
ret_value = 1;
178+
goto done;
163179
}
164180
else {
165181
LOG_INFO("Rank %d Successfully closed container c1\n", rank);
@@ -168,6 +184,7 @@ main(int argc, char **argv)
168184
if (PDCprop_close(obj_prop) < 0) {
169185
LOG_ERROR("Rank %d Fail to close property\n", rank);
170186
ret_value = 1;
187+
goto done;
171188
}
172189
else {
173190
LOG_INFO("Rank %d Successfully closed object property\n", rank);
@@ -176,6 +193,7 @@ main(int argc, char **argv)
176193
if (PDCprop_close(cont_prop) < 0) {
177194
LOG_ERROR("Rank %d Fail to close property\n", rank);
178195
ret_value = 1;
196+
goto done;
179197
}
180198
else {
181199
LOG_INFO("Rank %d Successfully closed container property\n", rank);
@@ -184,7 +202,10 @@ main(int argc, char **argv)
184202
if (PDCclose(pdc) < 0) {
185203
LOG_ERROR("Rank %d Fail to close PDC\n", rank);
186204
ret_value = 1;
205+
goto done;
187206
}
207+
208+
done:
188209
#ifdef ENABLE_MPI
189210
MPI_Finalize();
190211
#endif

0 commit comments

Comments
 (0)